1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

PHP Help Needed

Discussion in 'PHP & Perl' started by TheMonster786, Mar 26, 2015.

  1. TheMonster786

    TheMonster786 BANNED BANNED

    Joined:
    Dec 14, 2013
    Messages:
    160
    Likes Received:
    38
    I need a simple PhP coding Help .

    i want to show the Area Code of USA visitor's According to their Location .

    For Example , if any visitor comes from "Alaska" , it will show the Area Code of Alaska " 907".

    Hope to get solution Soon ...


    Thanks in Advance ...
     
  2. Free90Fly

    Free90Fly Newbie

    Joined:
    Mar 16, 2015
    Messages:
    3
    Likes Received:
    0
    Location:
    Taiwan
    you can do that by using geoip_record_by_name php function :) I can't post links yet, but you can check it out by yourself on the official documentation
     
  3. TheMonster786

    TheMonster786 BANNED BANNED

    Joined:
    Dec 14, 2013
    Messages:
    160
    Likes Received:
    38
    i just need to show the Area Code ....

    What would be the PHP code for it ?
     
  4. kaptain1

    kaptain1 Junior Member

    Joined:
    Jan 30, 2015
    Messages:
    102
    Likes Received:
    16
    Occupation:
    Freelance
    this is through 3rd party service requires some extra load time,
    you can replace "city" mentioned below to get your info
    Note: you will not be able to get info if this website is down
    $ip = $_SERVER['REMOTE_ADDR'];
    $details = json_decode(file_get_contents("http://ipinfo.io/{$ip}/json"));
    echo $details->city; // -> "Mountain View"
     
  5. ralphnsk

    ralphnsk Newbie

    Joined:
    Nov 2, 2009
    Messages:
    43
    Likes Received:
    13
    Gender:
    Male
    Location:
    /dev/random
    Hey,

    it should be something like this:
    Code:
     include('geoipcity.inc');
     $gi = geoip_open('GeoLiteCity.dat',GEOIP_STANDARD);
     $surfer_loc = geoip_record_by_addr($gi,$_SERVER["REMOTE_ADDR"]);
     echo $surfer_loc->area_code;