Good day.

It is necessary to add the ability to remember the user to the user authorization system, if he has checked the box “remember me” during authorization. I log in through the session. Those. checked the user data with data from the database and recorded the data in the session.

How to implement "remember me" - if the user clicked a tick, then when I write the data in the session about authorization, I write and cookies -

setcookie('login', $foo1 ,time()+604800, "/");setcookie('pass', $foo2 ,time()+604800, "/"); 

When logging out, I kill the session and delete the cookies -

 setcookie ("login", "", time()-14800); setcookie ("pass", "", time()-14800);session_destroy(); 

But the problem is that during the login session, the session is deleted, but there are no cookies, I do not know why.

Further, on the authorization page, where I have a redirect, a method is called after logging out, this method checks for the presence of cookies and, if they exist, check the data from the cookies and authorize the user. But due to the fact that the cookies did not go away while logging out, the session starts again and the user is logged in, so I cannot log out at all. I thought it was in the browser, but I tried it in chrome and in Exloer and in Mazil. I myself can not figure out what the reason is already 2 days. I really need help.

 static function saveMe(){ // проверяем наличие куки в браузере пользователя if(isset($_COOKIE['login'])){ if(!empty($_COOKIE['login']) && empty($_SESSION['mail'])){ // кука найдена, теперь сверим данные пользователя с данными в БД сайта $db = new db('yes'); $findUser = $db->isset_user($_COOKIE['login'],$_COOKIE['pass']); if(!empty($findUser['id'])){ $_SESSION['okauth'] = true; $_SESSION['mail'] = $findUser['mail_user']; $_SESSION['privileged'] = $findUser['privileged']; } unset($db); } } } 
  • @juniorspecialistphp, To format the code, select it with the mouse and click on the 101010 editor button. - Nicolas Chabanovsky
  • @juniorspecialistphp to thank the author, click on "Thumb Up" and the "Accept the Answer" button. - Oleg

1 answer 1

 setcookie("login", "", time()+604800, "/"); setcookie("pass", "", time()+604800, "/"); session_destroy(); 
  • Thanks, how simple it all turned out to be :-) - juniorspecialistphp