Jump to content

PHP Login System with Sessions


mds1256

Recommended Posts

validate the users credentials to the credentials in the database, if they are valid set a session like $_SESSION['logged_in']. a user may only enter if that session is set.

 

Thanks, so is this secure in that no one can just tamper with anything to add a session variable of logged_in with a value of 1?

 

Also how do you then retrieve data about a user from the database it will need some type of reference number, should that be stored in the session too?

Link to comment
Share on other sites

Actually, the best way of handling a user log in is to authenticate the visitor by checking their entered username/password against the database user table and then if there is a match you would store their user id and display information, such as usename, in session variables and switch their logged in/out status to 'logged in' in the user table along with updating the last logged in date/time. The user id stored in the session variable would only serve to identify the visitor. You would then use their identifying user id on each page request to query for their logged in/logged out status and any user permissions or privileges from an ACL (Access Control List) to determine what they can do on any page or what content is displayed on any page for that visitor.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.