Jump to content

Session control for authentication


mostafatalebi

Recommended Posts

Hello everybody

 

What is the best way to check if the user accessing a restricted page is logged in?

 

Currently, I use the following method:

 

if(isset($_SESSION['username']))

{

      // redirect to the homepage

}

else

{

// render the page

}

 

################################

 

but i think it's too simple and can easily be ripped. Isn't there any other way? For instance is it good to store the password in a session (in the time of logging in) and co-check with username session?

 

Thanks in advance

Link to comment
Share on other sites

Since the session is stored on the server (generally) you don't have to worry about it being altered. Put the bare minimum into the session: user ID/name, access level, maybe a couple other things that you might want to know frequently. You don't have to (and shouldn't) store the password in there since it's not like you have to authenticate the user with every request.

 

Maybe you're confusing sessions with cookies? Cookies are unsafe, and while a cookie is used to locate session data the actual data itself is safe.

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.