Re: finding the ip adres of the visitor of a web site.

Jeroen Massar <[email protected]> Sat, 21 Jan 2006 23:10:04 +0100
Newsgroups gmane.network.ipv6.general
Organization Unfix
Message-ID <[email protected]>
mustafa sahin wrote:
> Hi to all IPv6 users,
> 
> Does anyone know how can i learn the ip adres of a client that is
> connected to my web site, and whether he/she uses IPv6 address or not,
> like www.kame.net and www.sixxs.net does at the bottom of their sites.
> Is there any open source script for this.

See http://www.php.net/getenv/ and actually I don't think anyone would
be able to put a license on such a piece of code ;)

> I will also appreciate if someone can tell
> me how it is done, rather that the code itself...

Short version:

Webservers pass the REMOTE_ADDR in the environment variables to scripts.
Also see: http://hoohoo.ncsa.uiuc.edu/cgi/env.html

Long version:

Webclient connects to the server using TCP/IP(v4|v6). Server thus has a
connection from the client to the server and knows the IP addresses of
both ends. It uses getpeerinfo() to retrieve the remote address and puts
it in the REMOTE_ADDR enviroment variable and calls the scripting
language. This contains something like:

<?php
echo $_ENV['REMOTE_ADDR'];
?>

Et tada, the address of the client is on the screen.

For clients behind proxies, the proxy should add a "Forwarded-For:"
header in the HTTP request it sends to the server, which Apache stuffs
in the HTTP_X_FORWARDED_FOR environment variable, which can be found with:

<?php
echo $_ENV['HTTP_X_FORWARDED_FOR'];
?>

Greets,
 Jeroen
signature.asc (application/pgp-signature, 238 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2 (MingW32)
Comment: Jeroen Massar / http://unfix.org/~jeroen/

iD8DBQFD0rFAKaooUjM+fCMRAhNhAKCL7uZ15m54cKSsti+YtqTaNAh9JACfUcvI
QAQoOI7p3ijRAdf/U6I/V3w=
=vIDR
-----END PGP SIGNATURE-----