Home > Backend Development > PHP Tutorial > PHP - Get visitor information_PHP tutorial

PHP - Get visitor information_PHP tutorial

WBOY
Release: 2016-07-13 17:37:54
Original
1523 people have browsed it

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.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486515.htmlTechArticleMany website visit statistics programs provide source information. When customers check the statistics, they can learn where the visitors come from. The website is connected. The so-called origin is actually where others clicked from...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template