Re: Can I get the IP address from a visitor?

From: Date: Wed, 02 Dec 2009 07:57:42 +0000
Subject: Re: Can I get the IP address from a visitor?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-300197@lists.php.net to get a copy of this message
I happen to have grabbed this function from php.net a while back, and have been using it since: // by "fr600 at hotmail dot com" at http://us2.php.net/getenv function getip() { if(getenv('HTTP_CLIENT_IP') && strcasecmp(getenv('HTTP_CLIENT_IP'), 'unknown'))
    $ip = getenv('HTTP_CLIENT_IP');
  else if(getenv('HTTP_X_FORWARDED_FOR') && strcasecmp(getenv('HTTP_X_FORWARDED_FOR'), 'unknown'))
    $ip = getenv('HTTP_X_FORWARDED_FOR');
  else if(getenv('REMOTE_ADDR') && strcasecmp(getenv('REMOTE_ADDR'), 'unknown'))
    $ip = getenv('REMOTE_ADDR');
  else if(isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], 'unknown'))
    $ip = $_SERVER['REMOTE_ADDR'];
else
    $ip = 'unknown';
return($ip); } though as others have pointed out, IP address is not a very good way to uniquely identify visitors (at least not on its own). Lars Kristiansson wrote:
Hi! This is probably the wrong forum. Please redirect me if im out of place. I would like to find out what IP address my visitor uses when visiting a php script page on my domain. This page would contain a form in which the visitor would state his/her message. My goal is to create purchase-orders written on unique files, and to separate them my idea was to baptize files with the IP addresses, which would ive each visitor an unique purchase-order... Any hints to a newbie? Cheers, Lars


« previous php.general (#300197) next »