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:
- checks see if remember cookies set
- queries database find user_id associated hashed username in cookie
- gets password user_id user table
- gets salt remember_cookies table
- 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
Post a Comment