1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Find Location For IP Address

Discussion in 'PHP' started by Katypeterson, Jan 27, 2014.

  1. #1
    Hi Friends
    I need example code in php that is used to find the location of the obtained remote ip address.
     
    Katypeterson, Jan 27, 2014 IP
  2. Content Maestro

    Content Maestro Notable Member

    Messages:
    1,542
    Likes Received:
    789
    Best Answers:
    14
    Trophy Points:
    265
    #2
    Hi Katypeterson.
    Do you mean you have already obtained the IP address and want a sample PHP code to trace its geographic location (i.e. details like city, country etc.)?
    Here you will find the sample codes:
    http://www.daniweb.com/web-development/php/threads/153705/php-script-to-find-visitors-location
    http://stackoverflow.com/questions/...ation-from-the-ip-entered-through-a-input-box
    http://stackoverflow.com/questions/409999/getting-the-location-from-an-ip-address
    http://www.a2zwebhelp.com/visitor-location-in-php
    (I am not a programmer myself, but often try to google solutions for my coder friends.)
    Hope this helps.:)
     
    Content Maestro, Jan 27, 2014 IP
    Vooler likes this.
  3. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
  4. Code Developer

    Code Developer Active Member

    Messages:
    48
    Likes Received:
    2
    Best Answers:
    2
    Trophy Points:
    58
    #4
    http://chir.ag/projects/geoiploc/
     
    Code Developer, Jan 27, 2014 IP
  5. digitalpoint

    digitalpoint Overlord of no one Staff

    Messages:
    38,333
    Likes Received:
    2,613
    Best Answers:
    462
    Trophy Points:
    710
    Digital Goods:
    29
    #5
    digitalpoint, Jan 28, 2014 IP
  6. Murugesan.quadraincorp

    Murugesan.quadraincorp Greenhorn

    Messages:
    15
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #6
    Hi.
    The simple code using find IP adress....

    <?php

    if (getenv('HTTP_X_FORWARDED_FOR'))
    {

    $IP= getenv('HTTP_X_FORWARDED_FOR');
    $CIP = getenv('REMOTE_ADDR');
    echo "Proxy IP address is : ".$IP. "(via $CIP)" ;

    }

    else

    {

    $CIP= getenv('REMOTE_ADDR');

    print"IP address is : $CIP";


    }

    ?>
     
    Murugesan.quadraincorp, Jan 28, 2014 IP
  7. PoPSiCLe

    PoPSiCLe Illustrious Member

    Messages:
    4,623
    Likes Received:
    725
    Best Answers:
    152
    Trophy Points:
    470
    #7
    First - learn how to use code or php brackets around your code. Second, that could easily have been reduced to this:
    
    <?php
      echo $IP = (getenv('HTTP_X_FORWARDED_FOR')) ? 'Proxy IP address is:'.getenv('HTTP_X_FORWARDED_FOR').' (via'.getenv('REMOTE_ADDR').')' : 'IP address is: '.getenv('REMOTE_ADDR');
    ?>
    
    PHP:
    One line. However, this does nothing of what the OP was asking for - this only shows the IP-address, it does not provide a location.
     
    PoPSiCLe, Jan 28, 2014 IP
    digitalpoint likes this.