Redirect back to login page when BACK button is pressed?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
aditi_19
Forum Newbie
Posts: 23
Joined: Sun Jun 21, 2009 3:09 pm

Redirect back to login page when BACK button is pressed?

Post by aditi_19 »

I am having a logout.php page which successfully logs out the user destroying all the session variables. But when i use the Back button of the browser, I am still able to see the last page when the user was logged in.

How can i redirect a page to login page when a Back button from the browser is pressed, once the user has logged out?

Logout.php

<?php
session_start();

if (isset($_SESSION['username']))
{
ob_end_clean();
$_SESSION = array();
session_destroy();
header( 'Location: ../Index.php' ) ;
exit();
}
?>

Please tell me if there is a php function to redirect the back button press to login page !
User avatar
Skara
Forum Regular
Posts: 703
Joined: Sat Mar 12, 2005 7:13 pm
Location: US

Re: Redirect back to login page when BACK button is pressed?

Post by Skara »

I'm not sure if you have an issue here or not. Assuming your code works as intended, it's possible using the back button will still generate the same result. The client's browser will still retain history and cache--you have no control over deleting this, and as such some information will be stored on the client's computer regardless.
Although--and someone correct me if I'm wrong--I do believe you have some control over the caching of websites, although there's nothing to stop a browser from ignoring cache headers.
aditi_19
Forum Newbie
Posts: 23
Joined: Sun Jun 21, 2009 3:09 pm

Re: Redirect back to login page when BACK button is pressed?

Post by aditi_19 »

Is there no way the problem could be solved?
DJNed
Forum Newbie
Posts: 7
Joined: Sun Jul 05, 2009 6:20 pm

Re: Redirect back to login page when BACK button is pressed?

Post by DJNed »

Because you've killed the session, whatever they do on the cached page won't have any effect if it requires them to be logged in, such as clicking on certain links. Thus there should be no security risk, and the fact that the user was previously logged in means they can theoretically be trusted with any information that might be on display on the previous page, given that they were previously logged in while viewing that page. But as Skara said, there isn't really anything you can do concerning the user's browser cache. It's an inconvenience, sure, but not really a big problem.
Post Reply