Skip to content Skip to sidebar Skip to footer

Php/html - Http_referer

I am creating a website and on one particular page, am wanting to send the user back to the previous page. I am fairly new to PHP/HTML and have been using some existing code for id

Solution 1:

Don't rely on the HTTP Referrer being a valid or even non-empty field. People can choose to not have this set leaving any checks for that variable going to the empty side of the IF-ELSE clause.

You can guard against this by sending along a parameter in either the URL or POST parameters that would hold a value that you can use to redirect the user back to.

Solution 2:

You need to use:

$_SERVER['HTTP_REFERER']

Solution 3:

If you wanted to send the person back to the previous page and have it work regardless of the referrer being set correctly, you can append a GET parameter to the URL (or POST).. you will need to encode the URL.. Something like

http://www.domain.com.au/script.php?return=http%3a%2f%2fwww.domain.com.au%2fthis-is-where-i-was%2f

You can use PHP's urlencode() function.

Solution 4:

Also note that the referer header might be empty or missing anyway, so you shouldn't rely on it at all..

Solution 5:

You should use

$_SERVER['HTTP_REFERER']

However look at the register_globals configuration in php.ini, it should be turned off due to security reasons. You can read more on PHP Manual site.

Post a Comment for "Php/html - Http_referer"