Jump to content

Cookie not saving


dannon

Recommended Posts

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.

Edited by dannon
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.