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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.