Attempting to add a “keep me logged in”. Not exactly sure what I’m doing wrong, but on the initial login when “keep me logged in” is checked, this will run:
$email_and_password = array($email_from_html, $pass_from_html);
setcookie("StayLoggedZod", $email_and_password, time()+3600*24*30);
$email_from_html & $pass_from_html are the user’s email and password being stored into an array and that being stored into a cookie.
Now when you go back to the site after leaving, the initial page does this:
if (isset($_COOKIE['StayLoggedZod']))
{
$email_and_password = $_COOKIE['StayLoggedZod'];
$stored_email = $email_and_password[0];
$stored_password = $email_and_password[1];
//USES THE E-MAIL AND PASS STORED IN HERE TO LOG INTO WEBSITE VIA MySQL DB, I EXCLUDED THIS CODE BECAUSE I KNOW THIS PART WORKS.
}
else
{
header("location:login.php");
}
It returns no errors, I couldn’t get it to work so I made a quick test page like this:
$cookie_data = $_COOKIE['StayLoggedZod'];
$the_email = $cookie_data[0];
$the_pass = $cookie_data[1];
$display_string = "This is my email".$the_email.". This is my password".$the_pass;
echo $display_string;
No data shows up aside from “This is my email” ect.
This is my first time making a keep my logged in, not sure what I’m missing, hope I was thorough with my explanation.
-Mike
1) you should not store sensitive details like the password in a cookie. Cookies are stored on the client side and are editable and visible
2) check the man page for setcookie http://php.net/setcookie
you will see that the second parameter (the value that you want to store) should be a string (so if you want to store arrays think of a method to store them as a string like serialization or json encoding)