...

View Full Version : Login script to go back to page you were just on



treeleaf20
11-04-2009, 03:27 PM
All,
If I have a login link on the top of every page. How can I go to my login script and have it redirect back to the page that I was just on?

Thanks.

abduraooft
11-04-2009, 03:34 PM
You may send an extra variable in that link to indicate the page from which the link is clicked and write a switch -case block to compare this value in the login page to decide the target page.

treeleaf20
11-04-2009, 03:41 PM
Do you have an example on how to do this? Appreciate it.

abduraooft
11-04-2009, 03:55 PM
That depends on your system. I use a variable $page in all my pages(obtained from parsing $_SERVER['REQUEST_URI']) and my login link would look like

<a href="login.php?page=<?php echo $page;?>">Login</a> or

<a href="/login/<?php echo $page;?>/">Login</a>(in case of a friendly url setup :))

My login.php page reads the request from $_GET['page'], and stores this value in session or a hidden variable.

On a successful login, a switch block like

if(!empty($_SESSION['page'])){
switch($_SESSION['page'])
case 'home': $target='index.php?page=home';
#or home.php or whatever
break;
case 'about': $target='index.php?page=about';
#or about.php or whatever
break;
...
}
unset($_SESSION['page']);
}
if(!isset($target))
$target='profile.php';
header("Location:". $target); #you may need to add the complete path here
Hope this helps.:thumbsup:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum