Geo redirecting script!!! anyone???

Discussion in 'Scripts' started by Rage, Jun 1, 2006.

  1. #1
    i am looking for a script like google that open pages of the country the site is being browsing from...

    EX: if i open site from China it should open page for china...

    etc...

    anyone know;s about this kind of script???

    Thanks
     
    Rage, Jun 1, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    If you have created specific pages for specific countries than all you need to do is obtain a database which matches IP ranges with countries. When the user visits your site, the main program serving pages would lookup the country for the IP address and send the correct content.

    You need to define a default page, which is sent if there is no country matched to the IP address. These things change over time, so it is important to keep the database relatively current.

    Most of these databases cost money to buy. There were a couple of free ones available a couple of years back.

    I do not have a site-wide implementation. I did create a script which did this for a subscription page -- delivering a local currency version. However, we have since stopped changing the page based on IP address and simply showing the default page first, with links to the alternate.

    This is the basic script I used:

    
    <?php
    @ $db = mysql_connect('localhost', 'name', 'password');
    $ip = $_SERVER["REMOTE_ADDR"];
    $country = strtolower( IP2Country($ip) );
    
    mysql_close();
    $url = "http://www.domain.com/" . $country . "/page.html";
    ?>
    
    
    <?php 
    // this function will convert an IP to a country // 
    function IP2Country($ip)
    { 
    
    $country_2 = "US";
    
    $query = "select country_2 from ip2country where inet_aton('$ip') between iplow and iphigh"; 
    $result = mysql_query($query); 
    if (mysql_num_rows($result) > 0)
    	{ 
            extract(mysql_fetch_assoc($result)); 
            }
    else	{ 
            $country_2 = "US"; 
            }
    return($country_2);
    
    }
    ?>
    
    Code (markup):
    The query section needs to be adjusted to take into account the structure of the database you are using.
     
    clancey, Jun 1, 2006 IP
  3. thes

    thes Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you can use GeoIP
     
    thes, Jun 2, 2006 IP