Page 1 of 1
detect pc's IP address using PHP
Posted: Sat Jul 21, 2007 4:24 am
by thematrixuum
anybody know how to code this function?
thanks..
Posted: Sat Jul 21, 2007 4:41 am
by volka
The webserver's or the client's ip?
Posted: Sat Jul 21, 2007 7:07 am
by feyd
There's no function.
Look in $_SERVER. Also note that if you're going to do something with the client IP it's unreliable to use.
Posted: Sat Jul 21, 2007 8:12 am
by philc
this code stores the user's ip into a variable called var_ip
Code: Select all
$var_ip = $_SERVER['REMOTE_ADDR'];
Posted: Sat Jul 21, 2007 8:24 am
by s.dot
It should be noted that $_SERVER['REMOTE_ADDR'] is not always set and will leave ugly NOTICE's on your page in the event that it isn't set (depending on your display_error configuration).
It would be wise to check for the existance of it first.
Code: Select all
if(!empty($_SERVER['REMOTE_ADDR']))
{
$ip = $_SERVER['REMOTE_ADDR'];
} else
{
//$_SERVER['REMOTE_ADDR'] not set
}