I had the same problem, and to solve it I put the following code in my "check login" include file:
// code to detect no login
session_start();
session_register('target');
$_SESSION['target'] = "http://" . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
header("Location: " . $loginpage);
This stores the user's original destination into a session variable. I then just have the login page check to see if target is set:
// code to authenticate login session_start() if (!empty($_SESSION['target'])){ $target = 'Location: ' . $_SESSION['target']; session_unregister('target'); header($target); } // if
I hope this helps, Grant
Beauford.2005 wrote:
Hi,
I am trying to figure out how to redirect a user back to a page but not
having much luck.
For example: I click on a menu item on my site which goes to a.php. This file includes another file that determines if they are logged in or not. If not, they are sent to login.php using header(:Location: .... ). How would I automatically redirect them back to a.php after they have logged in successfully. I have tried using HTTP_REFERRER, but it isn't redirecting.
Any help is appreciated.
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php