PHP can get the page from which you come, the usefulness of referer

Source: Internet
Author: User
When developing a web program, we sometimes need to get the page from which the user is connected, and the referer is used. It is an http protocol, so any language that can develop web programs can be implemented, for example, request. getHeader ("referer") in jsp ")

When developing a web program, we sometimes need to get the page from which the user is connected, and the referer is used.

It is an http protocol, so any language that can develop web programs can be implemented. for example, in jsp:

Request. getHeader ('referer ');

Php is $ _ SERVER ['http _ referer']. I will not give examples of other languages ).

What can it do? Here are two examples:

1. prevent unauthorized connection. for example, I am a software download website. on the download page, I first use a referer to determine whether the previous page is my own website. if not, I will clarify that someone has stolen your connection.

2. for the security of e-commerce websites, I use referer on the pages that submit important information such as credit cards to determine whether the previous page is my own website. if not, it may be a form written by hackers, to skip the javascript verification in your previous page.

Considerations for applying referer:

If I directly input a page with a referer in the browser, the return value is null (jsp). That is to say, the referer will only have content when it is connected from other pages.

I did an experiment. for example, if my referercode is in a.jsp, the webpage is B .htm, and c.htm is a page with iframe. it embeds a. jsp in iframe. Bytes

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.