PHP $_server[' http_referer ' to get the URL address of the previous page

Source: Internet
Author: User

PHP $_server[' Http_referer ']

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:

    1. Enter the URL directly to access the page.
    2. Javascript opens the URL.
    3. Javascript Redirection (window.location) URLs.
    4. Use meta refresh to redirect URLs.
    5. Use the URL of the PHP header redirection.
    6. A link in flash.
    7. 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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.