Jump to content

remember me option ...and persistent cookie


jimfog
 Share

Recommended Posts

Suppose the user has ticked the remember me option and comes back to the site...at which point I create a new cookie for him.

 

Of course there must be a check first IF a cookie has been set....so as to automatically login the user.

 

Question:

 

Code that checks the existence of coookie...should it be present at every site page?

Link to comment
Share on other sites

If they have ticked the remember me option...then of course they will be able to go in whatever page they want without entering their credentials..

 

That means...put such code in every page...which to leads to my current...problem...testing for session and/or remember me cookie seems to be non-trivial...especially if the site has two type of users(as in my case)...

 

I am trying to think the conditionals combination that will do the work here....

Link to comment
Share on other sites

what complicates things is that I have to check for the session also...along with the cookie.

Link to comment
Share on other sites

here is the source of my confusion:

as I said this site has two types of users....a regular user and a business user....some pages are only for the first and some pages are only for the second...to view.

 

Suppose now that the regular users is logged in(has ticked "remember me")....and then the business_user goes to access a page.

 

Since the business user has not ticked the remember me option he will be redirected to the login page...and here is where the problem begins.

This is the code in login.php:

 if(isset($_COOKIE['cookiename_reg']))//cookie related to the regular user       {     $username=checkcookie_reg($conn,true);//here the cookie is checked and if correct perform redirect     delete_cookie_token($conn,$username);//delete cookie     setcookie_pers($conn,$username,'regular_user');//create a new one      }      elseif(isset($_COOKIE['cookiename_buz']))//cookie related to the business user      {     $username= checkcookie_buz($conn,true);     delete_cookie_token($conn,$username);      setcookie_pers($conn,$username,'buz_user');      } 

Since the regular user is already logged in...the first if statement runs and t business user is presented with regular_user_member.php

 

So I was confused by the above fact...until I realized that in the real world the regular users's machine will be different from the business_users's machine

Unless the reason for the above behavior is something else...

 

What do you think?I am just afraid that I miss something....maybe...I do not know.

Link to comment
Share on other sites

Would anyone be logged in as both kinds of user on the same machine?

I missed that crucial detail...

 

Totally agree with you in the other things you say.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...