environment variable to redirect user to referrer 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
abushahin
Forum Commoner
Posts: 42
Joined: Wed Nov 25, 2009 12:35 pm
Location: london

environment variable to redirect user to referrer page

Post by abushahin »

hi, i just wondered if i collect the http referrer using

Code: Select all

$_SERVER['HTTP_REFERER'];
inside a variable or hidden field how can i use this to send the user to that page after some sort of validation, i.e login.
ps, the user may have been browsing the page without logging in but when he presses a link to add comment he needs to login so how do i send the user to that page after login if that makes sense, many thanks abu
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: environment variable to redirect user to referrer page

Post by superdezign »

Don't bother using referrer. A user can set their browser to hide that information. What you want to do is send a GET variable to your login page. So, when an unregistered user tries to load a page:

Code: Select all

if (!$user->isValid()) {
  header("Location: http://domain.tld/login?lastPage=somePage");
}
Post Reply