Answer the question
In order to leave comments, you need to log in
How to make an eternal session in PHP when logging into an account?
Tell me, (just started working with PHP) how and where to write the code with remembering eternal cookies when the user logs in, so that the account is active until the user presses the logout button or clears the cookies through the browser on his own. I am attaching the login page:
<?php
require 'db.php';
$data = $_POST;
if ( isset($data['do_login']) )
{
$user = R::findOne('users', 'login = ?', array($data['login']));
if ( $user )
{
//логин существует
if ( password_verify($data['password'], $user->password) )
{
//если пароль совпадает, то нужно авторизовать пользователя
$_SESSION['logged_user'] = $user;
echo '<script type="text/javascript">location="index.php";</script>';
}else
{
$errors[] = 'Логин или пароль не совпадают';
}
}else
{
$errors[] = 'Логин или пароль не совпадают';
}
if ( ! empty($errors) )
{
//выводим ошибки авторизации
echo '<div id="errors" style="color:red; text-align:center;">' .array_shift($errors). '</div>';
}
}
?>
Answer the question
In order to leave comments, you need to log in
You need to set cookies upon successful authorization, and then check them when the server session has expired.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question