tags:

views:

60

answers:

3

instead of

login.php?ref=http://mysite.com/lastpage

could I get the before page somehow else? tried HTTP_REFERER but cant get it to work

Notice: Undefined index: HTTP_REFERER in C:\test\login.php on line 18

// Newbie

+3  A: 

HTTP_REFERER (and almost every other $_SERVER var) are not a reliable means of obtaining previous pages as they can be easily faked.

Setting a session variable could be slightly safer but will not work if they came from an external url. Afaik there is not a fool-proof method of accomplishing this.

Mike B
A: 

Use $_SERVER['HTTP_REFERER'] like this:

$ref=$_SERVER['HTTP_REFERER']

Lars D
A: 

The HTTP_REFERER is not always set, that's why you're getting the notice. The browser may opt not to send it or the user may have entered the URL directly into his browser. You can put that value into the session, which has other drawbacks (multiple tabs in the browser have the same referrer page, for example.) I think the url is still the best way to go, if you don't have a form, which you can append a hidden field to.

EDIT By the way: don't use the URL in the get parameter blindly, that can be faked again by others as explained in the answers to this other question.

soulmerge
but what if the page contains GET variables? like profile.php?id=234
Mladek
I provided several methods, which one do you mean?
soulmerge
Justin Poliey's, tried yours but couldnt get it to work i dont understand that type of array
Mladek
It's just the normal array syntax: http://php.net/manual/en/language.types.array.php
soulmerge