Tell me more ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I finally found my balance in getting auto login using cookie but I encountered a problem. Whenever I test the login with auto login checked. I close the browser and reopen it to test if it works. The weird thing is that I don't appear to be logged in but I actually am when I refresh.

if (isset($_SESSION['user_id'])) {

// Menu with links appear when logged in

}else{

// The login form

}

How do sites set it when users visit the page, the menu of a successful login appear?

share|improve this question
I think your browser is caching the content when you close and re-open the window. Try doing this: if(isset($_SESSION['user_id'])){header('Location: ./');} – ionFish Jul 15 '12 at 17:40
That wouldn't work since it would just keep redirecting. – taeja87 Jul 15 '12 at 18:11
Oh, my bad. I think it's an issue of browser caching. – ionFish Jul 15 '12 at 18:21
Alright. I'll look into that. – taeja87 Jul 15 '12 at 18:22
Personally what I always do, is at the top of the login page, do "if-authenticated, header-location (./content.php) else show-login-form." and then in content.php, "if-authenticated show-content else header-location (./) which will force the login form again. Actually, if you contact me (click my username, homepage, contact page) I would be more than happy to share some of my own login page sources that do what you're looking for. – ionFish Jul 15 '12 at 18:28

closed as off topic by Su', John Conde Jul 15 '12 at 23:36

Questions on Webmasters Stack Exchange are expected to relate to webmastering within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

Browse other questions tagged or ask your own question.