11-04-2009, 02:27 PM
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?
11-04-2009, 02: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.
11-04-2009, 02:41 PM
Do you have an example on how to do this? Appreciate it.
11-04-2009, 02: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
case 'home': $target='index.php?page=home';
#or home.php or whatever
case 'about': $target='index.php?page=about';
#or about.php or whatever
header("Location:". $target); #you may need to add the complete path here
Hope this helps.:thumbsup: