View Full Version : Best method to return user to last page after logging in.

12-04-2009, 02:35 PM
Hi guys,

What is the best method to return a user to the page they where on after they have logged in?

Thanks all.

Regards Paul

12-05-2009, 12:29 AM
good question, i think i would use
PHP $_SERVER['PHP_SELF'] to detect the page, pass that info as a GET value to the log in page, the in the 'location redirect' use it as a variable[

12-05-2009, 03:25 PM
Thanks for that Edbr.

I did a bit of googling and have found this little function.


function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
} else {
return $pageURL;


I saved it as getURL.php and included it in my page...


I then declared a variable from the function and then set it as a session so it can be picked back up as required.....


$returnURL = curPageURL();
$_SESSION['returnURL'] = $returnURL;

You will have to adjust this suit your own requirements but I hope it helps someone else.

Regards, Paul

12-07-2009, 12:50 AM
nice, is the https needed fo you?

12-07-2009, 05:56 AM
No not in the app I'm working on right now but I left it in for the example in case others needed it.

Regards, Paul