jimfog Posted August 28, 2015 Share Posted August 28, 2015 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 More sharing options...
justsomeguy Posted August 28, 2015 Share Posted August 28, 2015 You should answer that, how do you want your site to work? If they go to any page, should they be logged in or not? Link to comment Share on other sites More sharing options...
jimfog Posted August 28, 2015 Author Share Posted August 28, 2015 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 More sharing options...
justsomeguy Posted August 28, 2015 Share Posted August 28, 2015 If they are not currently logged in then check for the cookie and log them in. Link to comment Share on other sites More sharing options...
jimfog Posted August 28, 2015 Author Share Posted August 28, 2015 what complicates things is that I have to check for the session also...along with the cookie. Link to comment Share on other sites More sharing options...
justsomeguy Posted August 28, 2015 Share Posted August 28, 2015 I don't understand why you're confused by that. if (the session is not set){ if (the cookie is set) create the session else redirect}check the session dataAfter that code the session is always set, right? Link to comment Share on other sites More sharing options...
jimfog Posted August 29, 2015 Author Share Posted August 29, 2015 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 More sharing options...
justsomeguy Posted August 31, 2015 Share Posted August 31, 2015 Would anyone be logged in as both kinds of user on the same machine? If not, why separate cookies? Why not have the user type saved in the cookie or session instead of using a different cookie for the user type? Link to comment Share on other sites More sharing options...
jimfog Posted August 31, 2015 Author Share Posted August 31, 2015 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now