PHP setcookie function not saving cookies? -


i hoping might able small issue i'm having code i'm working on. please keep in mind, hobby site, aware there security holes. have written function called set_remember_cookies called login script , registration page when user checks "remember me" box.

a function on each secured page following:

  1. checks see if remember cookies set
  2. queries database find user_id associated hashed username in cookie
  3. gets password user_id user table
  4. gets salt remember_cookies table
  5. hashes password + salt , matches against hashed password in cookie

again, know insecure store hashed password in cookie, not worried now.

my problem set_remember_cookies function, have included below, not setting cookies. on secured pages, first step (checking if cookies exist) fails. have checked in browser cookies, , not stored.

can explain me why function not setting cookies? can't find errors, can! thanks!

    <?php       function set_remember_cookies($uid, $identifier, $password) {           mysql_query("delete remember_cookies user_id = '$uid'"); //delete old cookie records           $salt = sha1(uniqid(time() . $_server['http_referer']));           $username_hash = hash("sha256", $identifier . $salt); //hash username           if (mysql_query("insert remember_cookies (user_id, username_hash, salt) values ('$uid', '$username_hash', '$salt')")) {               setcookie("username", $username_hash, 60*60*24*365);               setcookie("password", hash("sha512", $password . $salt), 60*60*24*365);           }       }     ?> 

your cookies expired sometime in 1971! looks want offset 1 year in future, try

 setcookie("username", $username_hash, time() + 60*60*24*365); 

the third parameter isn't offset 'now', it's offset start of unix epoch - rather fine manuals make clear :)


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -