Get the page the user has viewed before the current one

instead

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

      

Can I get the page before anything else? tried HTTP_REFERER but couldn't get it to work

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

      

// Beginner

+2


source to share


3 answers


HTTP_REFERER is not always set, so you get a notification. The browser can refuse to submit, or the user can enter the URL directly into their browser. You can put this value in session , which has other drawbacks (for example, multiple tabs in the browser have the same referrer page.) I think url is still the best way if you don't have a form. to which you can add a hidden field.



EDIT . By the way: don't use a URL in the get parameter blindly, which might be spoofed by others again, as explained in the answers to this other question .

+1


source


HTTP_REFERER

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



Setting up a session variable might be a little more secure, but won't work if they come from an external url. Afayk is not a crazy method to achieve this.

+4


source


Use $ _SERVER ['HTTP_REFERER'] like this:

$ ref = $ _ SERVER ['HTTP_REFERER']

0


source







All Articles