If you are not under proxy then it is easy
$ip = getenv("REMOTE_ADDR");
But if you are, then:
$ip = getenv("HTTP_X_FORWARDED_FOR");
And here is the prob. This wariable is not always 100% valid. For example on some servers it will return just IP of the visitor on some others like Tripod you'll get something like "187.23.44.55, 187.23.44.55"
You have to substract the ip from this string.
So the code goes kinda like this:
$ip = getenv("HTTP_X_FORWARDED_FOR");
if($ip){
//parse here your result
//for lycos I had to kick that
// second copy of ip see link below
}else{
$ip = getenv("REMOTE_ADDR");
}
Click on these links to have a look:
Under proxy:
http://members.lycos.co.uk/horobey/testlab/iptest.php
No proxy:
http://horobey.jlxlinux.com/testlab/iptest.php