Http_referer header usage

Source: Internet
Author: User

When looking at the uchome and ecshop source code, we often find that the $ _ server ['HTTP _ referer'] value is used. HTTP Referer is a part of the header. When a browser sends a request to a Web server, it usually carries an HTTP Referer to tell the server which page the link is from, the server obtains some information for processing. For example, if a user is linked to a friend on my homepage, his server can calculate from HTTP Referer how many users click the link on my homepage to access his website every day. The following is an example to illustrate various changes in http_referer.

Please copy the followingCodeSave to a PHP file named referer. php:

 <  A  Href  = "? P = referer1"  Mce_href  = "? P = referer1"  > Referer1 </  A  > |  <  A  Href  = "? P = referer2"  Mce_href  = "? P = referer2"  > Referer2 </  A  >  |  <  A  Href  = "? P = referer3"  Mce_href = "? P = referer3"  > Referer3 </  A  >    <  HR  />    <?  PHP echo '['. $ _ server ['HTTP _ referer']. ']';  ?>   

 

Enter http: // localhost/hellophp/referer. php In the URL field. The execution result is as follows:

 
[]

 

Click Connect refer1. The execution result is as follows:

 
[Http: // localhost/hellophp/referer. php]

 

Click Connect refer2. The execution result is as follows:

 
[Http: // localhost/hellophp/referer. php? P = referer1]

 

Click Connect refer3. The execution result is as follows:

 
[Http: // localhost/hellophp/referer. php? P = referer2]

 

Click Connect refer1. The execution result is as follows:

 
[Http: // localhost/hellophp/referer. php? P = referer3]

 

In the URL bar, enter http: // localhost/hellophp/referer. php? P = referer2. The execution result is as follows:

 
[]

 

From the above process, we can draw the following conclusion:When a request is sent from the URL bar to the Web server, the value of $ _ server ['HTTP _ referer'] is null. When a request is sent from a link to the web server, the value of $ _ server ['HTTP _ referer'] is the requested URL.

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.