954,576 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How to direct "BACK" button of the browser to the Login page after Logout?

Hi,

I have created logout.php page which destroys all the session variables. Basically i want the the user to get directed to the Login page after logout button is pressed. But when the BACK button of the browser is pressed(even after logout), the user is still able to see other web pages.

How can i always direct Back button of the browser to Login page if the user has logged out?

aditi_19
Light Poster
34 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

Don't try to code the BACK button, instead, use something like this at the head of every page:

if(!isset($_SESSION['login']))header("Location: http://www.example.com/login.php");


Although you could use a relative or even absolute reference with header, I think I read somewhere that you should use the full url. Would cause a problem if testing both locally and remotely though. You could use:

if(!isset($_SESSION['login']))header("Location: {$_SERVER['HTTP_HOST']}/login.php");


to enable the same code to run on local, testing and remote servers

However, I've used absolute references in the past without any ill effects, but I guess some other contributors here could give you good reasons why you shouldn't do this.

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,792 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

Hey,

Thanks a lot. It worked fine !

aditi_19
Light Poster
34 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You