Drupal Tip #2: Display Information About Your Visitors

Every now and then you may want to access some information about a website visitor. You might want to provide this information to them or perhaps you want to display different text, images, etc. depending on what host they are from. This article highlights using some simple php code to retrieve visitor info such as ip address, hostname, browser type, etc. The following $_SERVER variables give you access to this information -

IP address of visitor:
$_SERVER['REMOTE_ADDR'] = 38.107.191.81

Hostname of visitor:
gethostbyaddr($_SERVER['REMOTE_ADDR']) = 38.107.191.81

Port used by visitor:
$_SERVER['REMOTE_PORT'] = 10542

Software used by visitor:
$_SERVER['HTTP_USER_AGENT'] = CCBot/1.0 (+http://www.commoncrawl.org/bot.html)

Referring page:
$_SERVER['HTTP_REFERER'] =

Page Request Timestamp:
date(DATE_RFC822, $_SERVER['REQUEST_TIME']) = Thu, 29 Jul 10 17:26:49 +0000