Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2009, 02:27 PM   PM User | #1
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
Login script to go back to page you were just on

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.
treeleaf20 is offline   Reply With Quote
Old 11-04-2009, 02:34 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 11-04-2009, 02:41 PM   PM User | #3
treeleaf20
Regular Coder

 
Join Date: Oct 2009
Posts: 438
Thanks: 9
Thanked 7 Times in 7 Posts
treeleaf20 is an unknown quantity at this point
Do you have an example on how to do this? Appreciate it.
treeleaf20 is offline   Reply With Quote
Old 11-04-2009, 02:55 PM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
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
PHP Code:
<a href="login.php?page=<?php echo $page;?>">Login</a>
or
PHP Code:
<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
PHP Code:
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:10 PM.


Advertisement
Log in to turn off these ads.