Reprint: http://www.5idev.com/p-php_server_http_referer.shtml
Using $_server[' Http_referer '] will make it easy to get the address of the previous page linked to the current page. An example is as follows:
index.php (actual address: http://www.5idev.com/php/index.php):
<a href= "test.php" > Links </a>
Test.php (actual address: http://www.5idev.com/php/test.php):
echo $_server[' Http_referer '];
In the browser access index.php, click Link to test.php, the resulting output is:
http://www.5idev.com/php/index.php
PHP $_server[' http_referer '] Invalid
It is important to note that $_server[' Http_referer ' is entirely from the browser. Not all user agents (browsers) will set this variable, and some can manually modify the Http_referer. Therefore, $_server[' http_referer ' is not always true and correct.
Normally, $_server[' http_referer ' will not work in some of the following ways:
- Enter the URL directly to access the page.
- Javascript opens the URL.
- Javascript Redirection (window.location) URLs.
- Use meta refresh to redirect URLs.
- Use the URL of the PHP header redirection.
- A link in flash.
- The browser is not set or modified by the user.
So in general, $_server[' http_referer ' is only valid for pages that are accessed through <a></a> hyperlinks and POST or GET forms.
Because $_server[' http_referer ' is also valid for POST form access, the form data processing page can be partly verified by validating $_server[' http_referer '] to prevent malicious submissions of forms. However, this method does not guarantee the absolute correctness of the form data, that is, the authenticity detection of the form data does not depend entirely on $_server[' http_referer '.
PHP $_server[' http_referer ' to get the URL address of the previous page