PDA

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


tux
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

edbr
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[

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

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

<?php

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

?>

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

include("getURL.php");

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

session_start();

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

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

Regards, Paul

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

tux
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