PHP Script to detect the Ip of the request

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    PHP Script to detect the Ip of the request

    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,

    #2
    PHP Code:
    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); 

    Comment


      #3
      Originally posted by Anshul View Post
      PHP Code:
      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.

      Comment


        #4
        you may wish to add*
        Code:
         else if($_user_ip=="unknown")$_user_ip = $_SERVER['REMOTE_ADDR'];
        for blackberrys*


        __________________

        mmmmmm tasty!
        Last edited by something else; 05.06.09, 01:45. Reason: because i can lol

        Comment


          #5
          Thanks a lot my friend.>

          Comment

          Working...
          X