PHP-get Visitor Information

Source: Internet
Author: User
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.

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.