Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Possibly the best approach, as has been suggested and what most third-party apps do, is to create a "user_sessions" database table with the following fields:</p> <pre><code>session_id (var_char) user_id (int) ip_address (var_char) last_logged_in (unix timestamp) </code></pre> <p>Then use a cookie to store an md5 hash of whatever you like, possibly:</p> <pre><code>md5($username.$ip); //since md5 has a lot of reverse look ups now you should use a number of fields to validate. You could use a different crypto function to make it more difficult to crack, but md5 is the simplest version available in all php versions. </code></pre> <p>EDIT: You will then compare the stored hash from the cookie with the database <strong>session_id</strong> to see if they have already logged in. The reason to combine a couple of fields in the md5 function is to create a less "guessable" hashing format. It makes it less likely someone will be able to edit a cookie and login as someone else.</p> <p>This could be done for all users (this way you can track who is online) and just set a "persistant" login variable in the cookie. eg.</p> <pre><code>p_login=true || p_login=false </code></pre> <p>That way you'll know whether to auto login or force login.</p> <p>note: You may be able to look at <a href="http://www.openwall.com/articles/PHP-Users-Passwords" rel="nofollow noreferrer">http://www.openwall.com/articles/PHP-Users-Passwords</a> for a different way to hash passwords, session_ids and users.</p>
 

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