Php find IP address, referring page and User Agent | |
PHP the $_SERVER variableWe will not be discussing all the $_SERVER variable contents here but a full reference may be found in the manuals Server Variable info page. We are interested in REMOTE_ADDR which is the IP address of the browsers machine, HTTP_USER_AGENT which often tells us lots of good stuff about their browser and machine, and HTTP_REFERER which tells us if they came here from another web page by clicking a link.REMOTE_ADDR $_SERVER[REMOTE_ADDR] will almost always be filled in. The content will simply be an IP address such as 192.36.132.21 HTTP_USER_AGENT $_SERVER[HTTP_USER_AGENT] Is often but not always filled in. It contains user details of browser and operating system. Some users block this info by using special security tools. this is often used to detect mobile phone users by parsing the returned string which may be something like 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12) Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12 GTB7.1' a big list of user agent strings is at www.useragentstring.com
HTTP_REFERER $_SERVER[HTTP_REFERER] Is often missing. When present it contains the URL of the web page that the user clicked on. This may be a search engine page in which case the query the user entered will also be returned such as:
Testing your $_SERVER PHP codeTo make this easier for you below we have a links list that you can add your page to, and click on it so you have valid referrer details.
$_SERVER Test Links
|
Tutorial Contents
$_SERVER Referrersbookmark hit - www.google.ca - www.google.co.in - www.google.com - ... - internal hit - xxsurl.com - www.google.co.uk - storage-bottles.com - ... - www.google.com.au - www.ask.com - www.google.com.tw - ... - ... - www.gurcan.com - www.google.co.th - www.google.com.hk - www.google.com.eg -This list of people who link to this $_SERVER Tutorial page is automagically maintained. Link to us, send traffic, and get listed. Simple. |