I have a simple web page in which the user will enter some information before submitting the form. I would like to retrieve his IPaddress after the post is done.
Asked
Active
Viewed 50 times
0
-
please look into $ip=$_SERVER['REMOTE_ADDR']; – Elen Jan 25 '12 at 12:47
2 Answers
1
Here is function from another relevant post that should help:
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
This will cover the occasional proxy user and shared networks.

Community
- 1
- 1

Jeremy Harris
- 24,318
- 13
- 79
- 133