By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,956 Members | 1,722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,956 IT Pros & Developers. It's quick & easy.

how to get client ip php

P: n/a
Hello friends,

I am using the function
of how to get client IP from my website but it always
give me the server ip not any client who send me the info..

function getIP() {
$ip;
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "UNKNOWN";
return $ip;
}

thanx in advance
Dec 20 '07 #1
Share this Question
Share on Google+
2 Replies


P: n/a
If you are testing this on your development platform (i.e from the
same computer) then the client IP and the server IP are one and the
same. It will probably work fine when you put it live on your site.
Dec 20 '07 #2

P: n/a
Rob
On Dec 20, 6:08 am, upendra...@gmail.com wrote:
Hello friends,

I am using the function
of how to get client IP from my website but it always
give me the server ip not any client who send me the info..

function getIP() {
$ip;
if (getenv("HTTP_CLIENT_IP"))
$ip = getenv("HTTP_CLIENT_IP");
else if(getenv("HTTP_X_FORWARDED_FOR"))
$ip = getenv("HTTP_X_FORWARDED_FOR");
else if(getenv("REMOTE_ADDR"))
$ip = getenv("REMOTE_ADDR");
else
$ip = "UNKNOWN";
return $ip;

}

thanx in advance
Have you tried $_SERVER["REMOTE_ADDRESS"] instead?
Dec 20 '07 #3

This discussion thread is closed

Replies have been disabled for this discussion.