Fwd: php-db Digest 11 Feb 2002 20:12:53 -0000 Issue 1046

From: Date: Tue, 12 Feb 2002 10:10:39 +0000
Subject: Fwd: php-db Digest 11 Feb 2002 20:12:53 -0000 Issue 1046
Groups: php.db 
Request: Send a blank email to php-db+get-16850@lists.php.net to get a copy of this message
My best shot (very reliable) is bodged together and adapted from various sources. Try this : $comes_from=array(HTTP_VIA , HTTP_X_COMING_FROM , HTTP_X_FORWARDED_FOR , HTTP_X_FORWARDED , HTTP_COMING_FROM , HTTP_FORWARDED_FOR , HTTP_FORWARDED); // This array *should* hold most of the possible headers identifying the remote IP address. // Credit to Marc.Meurrens@ACM.org for the list of http headers. foreach ($comes_from as $value) { if (ereg("^([0-9]{1,3}\.){3,3}[0-9]{1,3}",$$value,$remote_temp)) { $remote=$remote_temp[0]; // Fish out IP match if ereg returns a value }} if (! $remote) { $remote=$REMOTE_ADDR; } And thats it. If your user has a *real* IP address you get $remote set to value of $REMOTE_ADDR, else it fishes out any forwarded address from the proxy and returns that ;-) Use gethostbyname to lookup the hostname from IP address. Cheers, Neil Smith. >----- Original Message ----- >From: "Jeroen Timmers" <maillist@start4me.nl> >To: <mlists123@yahoo.com> >Cc: "[PHP-DB]" <php-db@lists.php.net> >Sent: Monday, February 11, 2002 7:43 AM >Subject: [PHP-DB] Re: [PHP] help - to get client IP > > > > Someone please help me of how I could get the client IP using PHP, when i > > use $remote_addr it gives me the server IP, Kindly help how I could get >the > > IP of clients who are connected to my server or website. > > > > $ip = gethostbyname($REMOTE_HOST); > > > > the you got the IP of the remote user. > > > > Jeroen Timmers > > > >

« previous php.db (#16850) next »