dannon Posted May 28, 2013 Share Posted May 28, 2013 Hello, I am working on a login system for my website, more specifically the remember me feature. I have made it so my PHP script saves an authentication token as a cookie, and then encrypts the token and then saves the encrypted token into a database when the user logs in.If the cookie is already set and there is no session, the application will validate the cookie and then generate a new token and then log the user in. I have tested the remember me feature by removing the PHPSESSID, to check whether or not the remember me feature will use the cookie correctly to log me back it. However, I have noticed that sometimes the cookie would not update, thus causing me to stay logged out and preventing me from logging in again. Is there a way to fix this? If you are wondering, here is my code that updates the token: public function updateCookie($username) { $randomString = $this->generateString(); setcookie("rm_session", $username . "-" . $randomString, strtotime('+1 month'), "/"); Model::$db->preparedQuery("INSERT INTO remember_auths (username, token) VALUES(:username, :token)", array( ":username" => $username, ":token" => $this->cryptString($randomString) )); } I am also trying to make the cookie HTTP only; however, for some reason it is not letting me to set a domain, every time that I set a domain, the cookie doesn't show up. It's most probably because I am using the RewriteEngine. Is there a way to fix this aswell? I have tried using the domain as localhost, null, false and 127.0.0.1, but it didn't work. Link to comment https://forums.phpfreaks.com/topic/278497-cookie-not-saving/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.