Many website access statistical programs provide information on the routes from which visitors access the website. The so-called road is actually where someone else clicks the link to your website, that is, from what page to connect to your website. In PHP, it is very simple to obtain the information of the Origin path. we only need to use referer. Information carried by the HTTP header "> <LINKhref =" http: // www. php100.
Many website access statistical programs provide "routes". when you view the statistical data, you can find the website from which the visitor connects. The so-called "come to the road" is actually where someone else clicks the link to your website, that is, from what page to connect to your website.
In PHP, it is very simple to get the "coming" information. we only need to use referer. The information contained in the HTTP header contains a variable $ _ SERVER ['http _ referer'], which provides the complete URL address of "origin. Run the following code in your PHP page script to print the specific address ("") of the page to which the script is located "):
$ V_url = $ HTTP_REFERER;
Print $ v_url;
For example, if you click your website from the link on this site, you will get a URL address similar to "http://www.php100.com/forum.pdf. That's simple.
The URL may be long. As a route address, in many cases, we may only care about which website it belongs to, that is, what is the website's virtual host name. A url contains entity information, including:
· Solution (scheme)-HTTP
· Host-www.php100.com
· Path-/forum
PHP provides a simple method to intercept the Entity Information: parse_url () function. The parse_url () function parses a URL and returns an array containing the preceding entity and other information such as port and querry. Labels:
$ V_url = 'http: // www.php100.com/forum/reg.php'; // URL to be processed
$ Str_ar = parse_url ($ v_url );
$ V_host = $ str_ar ['host'];
Print $ v_host;
Execute the above script, and the browser will display: www.php100.com, that is, the virtual host name of this site.