Web Hosting Info

Search:

featured partner

The IP to Country Database

Handbook

Example code to detect country
Last updated by amit on Thu, 09/25/2003 - 03:00
<?

    //---------------------------------------------------
    // Sample code to display Visitor Country information 
    // PHP 4 
    //---------------------------------------------------


    // Establishing a database connection
    $dbh=mysql_connect("localhost:3306","$MYSQL_USERNAME","$MYSQL_PASSWORD");
    mysql_select_db("$MYSQL_DBNAME");


    // Query for getting visitor countrycode
    $country_query  = "SELECT country_code2,country_name FROM iptoc ".
         "WHERE IP_FROM<=inet_aton('$REMOTE_ADDR') ".
          "AND IP_TO>=inet_aton('$REMOTE_ADDR') ";


    // Executing above query
    $country_exec = mysql_query($country_query);


    // Fetching the record set into an array
    $ccode_array=mysql_fetch_array($country_exec);


    // getting the country code from the array
    $country_code=$ccode_array['country_code2'];


    // getting the country name from the array
    $country_name=$ccode_array['country_name'];


   // Display the Visitor coountry information
   echo "$country_code - $country_name";


   // Closing the database connection
   mysql_close($dbh);


?>
    Comment viewing options:
    Select your preferred way to display the comments and click 'Save settings' to submit your changes.
    Inet_aton() function not supported
    Posted by kunwarbs on Wed, 08/23/2006 - 11:35.
    My website supports PHP Version 4.3.2 and inet_aton() function is not supported by this version of php..

    pls suggest
     
    $REMOTE_ADDR didn't work for
    Posted by krypton1 on Thu, 03/15/2007 - 02:20.
    $REMOTE_ADDR didn't work for me and I had to use $_ENV['REMOTE_ADDR'] So here is the new piece of code:
      // Query for getting visitor countrycode
      $country_query  = "SELECT country_code2,country_name FROM iptocountry ".
           "WHERE IP_FROM<=inet_aton('".$_ENV['REMOTE_ADDR']."') ".
            "AND IP_TO>=inet_aton('".$_ENV['REMOTE_ADDR']."') ";
    
    Thanks fot the code
    Posted by suntech on Sun, 04/01/2007 - 18:47.
    www.floristavenue.com
    www.topindianflorist.com
    Iz pr
    Posted by Jomas56 on Sun, 04/29/2007 - 02:09.
    What happened? fetish toons That fetish toons and cartoons. big boobs hardcore I see on her big boobs hardcore. asian teen sucking Asian teen sucking is very good. anal cream pies There are anal cream pies, isn't it? mature big dildos Mature big dildos are attractive. lesbian dildo movies Watch lesbian dildo movies on plasma. gay cock hard His gay cock hard moving into Jack. ass big wet His ass big wet and smooth. teens tricked Teens tricked are very interesting. cum pussy wet Her cum pussy wet is pretty. mature beauty ass Dan said: " mature beauty ass ." teens undressing There some teens undressing in the diner-room. lesbian double dildo What do you think about lesbian double dildo? big boobs in There are big boobs in her red dress. asian undressing See! That asian undressing! anal cum extreme Anna has anal cum extreme. It is weather.