Login Previous Page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jboku
Forum Newbie
Posts: 10
Joined: Tue Nov 17, 2009 10:31 am

Login Previous Page

Post by jboku »

Hey guys,

I have a script I've written and it's working except for 1 problem, if I try and use the $_SERVER['HTTP_REFERER']; to send it back to the previous page, it takes me to a blank page w/ nothing on it. If I set my variable to say, google.com it works fine.

Code: Select all

$ref=$_SERVER['HTTP_REFERER'];
header( 'Location:' .  $ref );
Basically I want the person who logs in to be sent back to the page they came from.

Any help would be greatly appreciated.

Thanks
thefarhan
Forum Newbie
Posts: 5
Joined: Tue Dec 22, 2009 7:02 am

Re: Login Previous Page

Post by thefarhan »

u should write direct path to that page like header(''location:login.php'');
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Login Previous Page

Post by AbraCadaver »

And you can't always rely on HTTP_REFERE. You should set a session var on each page that holds the current page and then on your login page you can redirect back to that.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
manohoo
Forum Contributor
Posts: 201
Joined: Wed Dec 23, 2009 12:28 pm

Re: Login Previous Page

Post by manohoo »

I second AbraCadaver suggestion. If the page in question is bookmarked, and previous to that the user was in, let's say cnn.com... what would happen? An undesirable outcome!
Post Reply