Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP setcookie function not saving cookies?
    primarykey
    data
    text
    <p>I was hoping someone might be able to help with this small issue I'm having with some code I'm working on. Please keep in mind, this is just for a hobby site, I am aware there are security holes. I have written a function called set_remember_cookies that is called from my login script and registration page when the user checks the "remember me" box. </p> <p>A function on each secured page then does the following:</p> <ol> <li>Checks to see if the remember cookies are set</li> <li>Queries the database to find the User_ID associated with the hashed username in the cookie</li> <li>Gets the password for that User_ID from the user table</li> <li>Gets the salt from the remember_cookies table</li> <li>Hashes the password + salt and matches it against the hashed password in the cookie </li> </ol> <p>Again, I know it is insecure to store even a hashed password in a cookie, but I am not worried about that now.</p> <p>My problem is that the set_remember_cookies function, that I have included below, is not actually setting the cookies. On the secured pages, the first step (checking if the cookies exist) fails. I have also checked in the browser for the cookies, and they are not stored. </p> <p>Can anyone explain to me why this function is not setting the cookies? I can't find any errors, but hopefully someone can! Thanks!</p> <pre><code> &lt;?php function set_remember_cookies($uid, $identifier, $password) { mysql_query("DELETE FROM remember_cookies WHERE User_ID = '$uid'"); //Delete old cookie records $salt = sha1(uniqid(time() . $_SERVER['HTTP_REFERER'])); $username_hash = hash("sha256", $identifier . $salt); //Hash the username if (mysql_query("INSERT INTO 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); } } ?&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload