Many website access statistics programs provide "original" information. When customers check statistical data, they can learn from which website the visitor connected. The so-called "origin" actually refers to where others clicked on the link to your website, that is, from what page they connected to your website.
In PHP, it is very simple to obtain the "source" information, we only need to use referer. The information carried by the HTTP header includes a variable $_SERVER[HTTP_REFERER], which provides the complete URL address of the "origin". Put the following code into your PHP page script, and it will print out the specific address (i.e. "origin") connected to the page where the script is located:
$v_url=$HTTP_REFERER;
Print $v_url;
For example, if a user clicks on your website from a friendly link on this site, you will get a URL address similar to "http://www.BkJia.com/forum". It's that simple.
The URL address may be very long. As a source address, in many cases, we may only care about which website it belongs to, that is, what is the virtual host name of the website. A URL address contains many entity information, mainly including:
·Scheme - HTTP
·Host - www.2cto.com
·Path - /forum
PHP provides a simple solution to intercept these entity information: parse_url() function. The parse_url() function parses a URL and returns an array, which contains the above entities and other information such as port and query. Preview:
$v_url=http://www.BkJia.com/forum/reg.php; //URL address 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.2cto.com, which is the virtual host name of this site.