The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Using Same Random Variable Twice

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
  • #25662


    I am working on a site where I need to generate an authentication key that will be stored in both a session variable and a cookie. I generate this key using the following.

    $auth_key = sha1(microtime() . rand(10000, 99999 ));

    I then go on to store this value in a cookie and session variable like this…

    setcookie(‘auth_key’, $auth_key, $expiration);
    $_SESSION[‘auth_key’] = $auth_key;

    The problem is that $auth_key generates a different value for the cookie and the session variable.
    Is there any way to turn the $auth_key (ie: random and microtime values) in to variable that does not change?
    In other words can PHP store a random variable in an unchanging variable?

    Any help would be much appreciated.



    Here is the sample code I am using:


    Using this, I am getting the same value for the session variable and the cookie data. You only set the auth_key variable once, and then use it in two places, so its value shouldn’t change between the two times that you use it.

    I’m using Firecookie (a plugin for the Firefox Firebug plugin) to compare session/cookie data.

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Back End’ is closed to new topics and replies.