I have a typical login (username, password), and I also want to enable "save my data". Login form. Will register its values ββfor login_script.php, and if the login is completed successfully, the user will be redirected to the main page of the site.
I am contacting this method to save login information
//Remember Me Function if(isset($_POST['remember_me'])){ // Set a cookie that expires in 24 hours setcookie("username",$username, time()+3600*24); setcookie("password",$password, time()+3600*24); }
Now, from what I understand, setcookie("username",$username, time()+3600*24); must be installed at the top of the PHP page before other code is executed.
My problem is that I do not want to set cookies if the user has not logged in. However, due to the fact that the cookie function, which is called in the middle of the script after the login test, does not work.
Any ideas? Greetings.
source share