Search code examples
sessionhttp-redirecthyperlinkheaderdestroy

Difference between hyperlink and address bar-browsing? (Issue concerning sessions)


I've got a problem concerning sessions. To make this short I have a login page which stores the POST-value of email in a session variable. I use this session to check whether the user has got the permission to enter specific pages or not. I also have a logout page, which destroys the session and redirects the user to the login page. This is where my problem occurs. When I go to my logout page by entering the URL in the address bar of my browser, the session gets destroyed and I'm successfully redirected back to the login page. However, when I make a link to the logout page using an a href-tag, and I click the link, I do get redirected, however the session is NOT destroyed. This really confuses me. I haven't forgot about session_start() or so on any page, of that I'm sure. Has anyone got any ideas?

I guess enclosing some code would be helpful:

Basically, this is my logout page:

<?php
session_start();
session_unset();
session_destroy();
header("Location: http://www.example.com/login");
?>

This is part of the code from the page where you can go to the logout page:

<a href="http://example.com/logout/index.php">Click here to logout!</a>

If you need more code or anything then please let me know.

Thanks on advance.

/C


Solution

  • You're moving from www to non-www so your session is killed in one of then and not the other. Just use either www or non-www but not both.