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.