Re: getting the IP address off a visitor

From: Date: Mon, 08 Jul 2002 13:46:34 +0000
Subject: Re: getting the IP address off a visitor
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-106084@lists.php.net to get a copy of this message
Here is a function a found on php.net that turns the IP. Everything that Justin said is true too. If they have a dial-up user or are behind a proxy server you can't track them. Also if you are saving this to a database table it will get very big fast, just like Justin said. I would create a table just for today's hits, then have a script run at 12:01 everyday that creates a summary record and saves it to another table. Then delete the records from the today hits. You could setup a crontab to run the script for you. function getip() { if (isSet($_SERVER)) { if (isSet($_SERVER["HTTP_X_FORWARDED_FOR"])) { $realip = $_SERVER["HTTP_X_FORWARDED_FOR"]; } elseif (isSet($_SERVER["HTTP_CLIENT_IP"])) { $realip = $_SERVER["HTTP_CLIENT_IP"]; } else { $realip = $_SERVER["REMOTE_ADDR"]; } } else { if ( getenv( 'HTTP_X_FORWARDED_FOR' ) ) { $realip = getenv( 'HTTP_X_FORWARDED_FOR' ); } elseif ( getenv( 'HTTP_CLIENT_IP' ) ) { $realip = getenv( 'HTTP_CLIENT_IP' ); } else { $realip = getenv( 'REMOTE_ADDR' ); } } return $realip; } _________________________________________ Mark McCulligh, Application Developer / Analyst Sykes Canada Corporation www.SykesCanada.com (888)225-6824 ex. 3262 mmcculli@SykesCanada.com ----- Original Message ----- From: "Sebastian Marcu" <sebimarcu@yahoo.com> Newsgroups: php.general To: <php-general@lists.php.net> Sent: Thursday, July 04, 2002 12:00 PM Subject: getting the IP address off a visitor > Hi there, > > I am new to PHP and need some help. > I was wondering if there is a way to get hold of the IP address of a site > visitor with PHP. I'm trying to develop an interaction where the server > would recognise a new visitor from a returning visitor via the IP address. > > Regards, > > > Sebastian > > > >

« previous php.general (#106084) next »