Hi guys, I'm developing a wap site and I'd like to detect the IP of the phone to display the content according to the IP so, do you know how I will be able to detect this value using PHP?
Thanks in advance,
Started on the old forum in June 2009 · view the original in the archive · old links redirect here
Hi guys, I'm developing a wap site and I'd like to detect the IP of the phone to display the content according to the IP so, do you know how I will be able to detect this value using PHP?
Thanks in advance,
if (isSet($_SERVER['HTTP_X_FORWARDED_FOR'])) $_user_ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
else if(isSet($_SERVER['HTTP_CLIENT_IP'])) $_user_ip = $_SERVER['HTTP_CLIENT_IP'];
else if($_SERVER['REMOTE_ADDR']) $_user_ip = $_SERVER['REMOTE_ADDR'];
else {$_user_ip = 'not detected';}
$_user_ip = preg_replace("/[^0-9.]/", "", $_user_ip);
if (isSet($_SERVER['HTTP_X_FORWARDED_FOR'])) $_user_ip = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(isSet($_SERVER['HTTP_CLIENT_IP'])) $_user_ip = $_SERVER['HTTP_CLIENT_IP']; else if($_SERVER['REMOTE_ADDR']) $_user_ip = $_SERVER['REMOTE_ADDR']; else {$_user_ip = 'not detected';} $_user_ip = preg_replace("/[^0-9.]/", "", $_user_ip);
Thanks, it did the trick.
you may wish to add*
else if($_user_ip=="unknown")$_user_ip = $_SERVER['REMOTE_ADDR'];
for blackberrys*
mmmmmm tasty!