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

Looking for a Geolocation script

Discussion in 'General Scripting Chat' started by premiumsource, Apr 4, 2011.

  1. premiumsource

    premiumsource Senior Member

    Joined:
    Apr 20, 2008
    Messages:
    863
    Likes Received:
    1,164
    Location:
    Paradise Island
    I am looking for a script that will display a geolocation on my site. It needs to be able to do something like Welcome visitor from (City). I am not looking for a script that pulls data from their ISP though. Any input would be appreciated. Thanks.
     
  2. makcprimo

    makcprimo Newbie

    Joined:
    Sep 15, 2010
    Messages:
    22
    Likes Received:
    5
    I would like to get something like that as well
     
  3. drkenneth

    drkenneth Executive VIP

    Joined:
    Nov 13, 2008
    Messages:
    285
    Likes Received:
    176
    Occupation:
    Developer/Entrepreneur
    Location:
    USA
    http://www.maxmind.com/app/geolitecity

    They have a free good library with monthly updates. (I'd recommend using the binary version unless you have some major need to use a database.) It's not as accurate as their paid version, but it's not half bad. (99.5% accuracy country-wise vs 99.8% and 79% vs 83% city-wise.) Their site also includes different template code for C, C#, PHP, Java, Pearl, etc.

    Example code links:
    http://www.maxmind.com/app/support
     
    • Thanks Thanks x 1
  4. goines

    goines Newbie

    Joined:
    Jan 30, 2011
    Messages:
    48
    Likes Received:
    13
    I have my own PHP script, which does that. PM if interested
     
  5. goines

    goines Newbie

    Joined:
    Jan 30, 2011
    Messages:
    48
    Likes Received:
    13
    Thanks for your PM trudat, but I just realize I can't respond to PMs while I don't have more than 15 posts. So I will share it here.

    Guys, firstly download geoip script here:

    mediafirecom/?fw89d42geuvskhb

    Upload it on your server

    Once you open it, you'll see something like this:

    Code:
    <?php
        // the function returns the ip address of the person viewing the page
        function userIP()
        {
            return (isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
        }
        
        //    here we include the necessary files for the geoip script
        include("./geoip/geoip.inc");
        include("./geoip/geoipcity.inc");
        include("./geoip/geoipregionvars.php");
        
        // we open the database file     
        $gi = geoip_open("./geoip/GeoLiteCity.dat", GEOIP_STANDARD);
        
        // we optain the necessary datails about the IP
        $rsGeoData = geoip_record_by_addr($gi, userIP());
        
        //close the database file
        geoip_close($gi);
            
        $city = ($rsGeoData->city);        // $city stores the name of the city coresponding to the IP 
        $randNr = rand(1000,2000);        // generate a random number between 1000 and 2000
        
        // because the accuracy of the data base is not 100% for every country
        // we show an alternative text if the city could not be found    
        if($city == ""){
            echo "[B]We`ve Found $randNr Black Singles in Your Area Online Now![/B]";
        }
        else{
            // show the message
            echo "[B]We`ve Found $randNr Black Singles in $city Online Now![/B]";
        }                
    
    ?>
    Bold text is what you need to edit.

    Lets say you have line "Welcome visitor from City on my website" ..you will need to place this text to:

    Code:
    if($city == ""){
            echo "[B]Welcome visitor from City on my website[/B]";
        }
        else{
            // show the message
            echo "[B]Welcome visitor from [U]$City[/U] on my website[/B]";
        }                
    If it's not clear, let me know and I will help you to install it.
     
    • Thanks Thanks x 1
    Last edited: Apr 5, 2011
  6. centerz

    centerz Newbie

    Joined:
    Apr 2, 2011
    Messages:
    6
    Likes Received:
    0
    Home Page:
    HTTP_X_FORWARDED_FOR - this is very frequently mistake of many programmers.

    Don't use it, becose this is http header and client can send anything in this header.

    PHP:
    function userIP()
        {
            return (isset(
    $_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']);
        }

    to


    PHP:
    function userIP()
        {
            return  
    $_SERVER['REMOTE_ADDR'];
        }
     
  7. digitzero

    digitzero Newbie

    Joined:
    Feb 11, 2010
    Messages:
    15
    Likes Received:
    2
    HTML5 supports Geolocation now, so use that for all the main browsers, and then code something with maxmind or another geoip service if you detect the browser doesn't support HTML5.