Good I have a doubt I have made a login but the problem is that if a user has not logged in you can enter the page by putting the extension; How can I verify if that person has logged in and if he has not already sent him to login??
<?php
session_start();
if (isset($_SESSION['user_id'])) {
header('Location: ./logueado/index.php');
}
require 'database.php';
if (!empty($_POST['email']) && !empty($_POST['password'])) {
$records = $conn->prepare('SELECT id, email, password FROM users WHERE email = :email');
$records->bindParam(':email', $_POST['email']);
$records->execute();
$results = $records->fetch(PDO::FETCH_ASSOC);
$message = 'Usuario o contraseña incorrectos';
if (count($results) > 0 && password_verify($_POST['password'], $results['password'])) {
$_SESSION['user_id'] = $results['id'];
header("Location: ./index.php");
} else {
$message = 'Lo siento el usuario o contraseña no existe';
}
}
?>