[Tutorial] How to Set Up Your Own GeoTargeting Script

Thanks crazyflx! Your posts are always high quality! Busy now, i have just bookmarked it and read and discuss later!

Thanks again guy!
 
I'll send you a PM right now crzyyoungn (don't worry, I know you won't be able to reply, but you won't need to).

Thanks hunghtq :)
 
May you have some picture for us which it will be good to understand for us ><:
Thank you
 
Hey Crazyflx,

Got your PM and sent you an email 2 days ago I hope I get a response soon with a discount link because your list goes public in 2 days.... I sometimes end up in people spam box so make sure to check that.
 
Thanks a lot @crazyflx, this is so easy to setup and it works like a charm :D
 
I've installed the script fine, just wondering, how would i get the script to show which city the person is located in?
 
hey crazy,

question - with this can I use it to plot people on Google Maps?

Here is what I am trying to accomplish.

When someone comes to my site, squeeze page, there will be a Google Map on it. On the map there will be a red balloon, actually several, but they will be around where the person is located.

Do you know of any code that can do this or if it can be done with database of information here?

Thanks!
 
Code:
<?php

//connect to db
$con = mysql_connect('localhost', '[COLOR=Red]YOUR DATABASE USERNAME HERE[/COLOR]', '[COLOR=red]YOUR DATABASE PASSWORD HERE[/COLOR]') or die(mysql_error());
 
 
mysql_select_db('[COLOR=red]YOUR DATABASE NAME HERE[/COLOR]', $con);
 
//Get the parameters
if ($_GET["ip"]){
  $ip = mysql_real_escape_string(trim($_GET["ip"]), $con);
} else {
  $ip = getenv('REMOTE_ADDR');
}

 
//Run the IP location query
$ipQuery = mysql_query("SELECT * FROM `ip_group_city` where `ip_start` <= INET_ATON('$ip') order by ip_start desc limit 1;", $con);
$ipData = mysql_fetch_array($ipQuery);
$nbResults = (bool)mysql_num_rows($ipQuery);
                     
$CountryCode = $ipData['country_code'];


[COLOR=red]if ($CountryCode == 'US'){header('Location: http://www.flags.net/UNST.htm');}
else if ($CountryCode =='DE'){header('Location: http://www.flags.net/GERM.htm');}
else if ($CountryCode =='CA'){header('Location: http://www.flags.net/CANA.htm');}
else {header('Location: http://blackhatworld.com');}[/COLOR]
?>

Every time I am searching for some sort of specific code its always a awesome thread by crazyflx I end up at! :)

About the redirect by country code above. Is it possible to rotate offers under each country. That code redirects visitors to one location but I need it to redirect visitors to rotated locations/offers if you get what mean?

Thanks for any help. Looks like I can't rep you yet again crazy until I spread the rep around. :D
 
Last edited:
I've spent a good bit of time since trying to figure out the code needed to rotate the urls myself. I don't know php so I can only play around with different examples from the web and figure it out from there.

Here is the code I am trying to use. From what I read it should work but it doesn't. It just goes to http://www.$url.com/ when I try using it. If anyone knows php can point me in the right direction that would be great.

EDIT: Check a few posts down for the working solution.

Code:
<?php

//connect to db
$con = mysql_connect('localhost', 'dbusername', 'password') or die(mysql_error());
 
 
mysql_select_db('dbname', $con);
 
//Get the parameters
if ($_GET["ip"]){
  $ip = mysql_real_escape_string(trim($_GET["ip"]), $con);
} else {
  $ip = getenv('REMOTE_ADDR');
}

 
//Run the IP location query
$ipQuery = mysql_query("SELECT * FROM `ip_group_city` where `ip_start` <= INET_ATON('$ip') order by ip_start desc limit 1;", $con);
$ipData = mysql_fetch_array($ipQuery);
$nbResults = (bool)mysql_num_rows($ipQuery);
                     
$CountryCode = $ipData['country_code'];

$urlsireland = array('www.ebay.com',
                    'www.amazon.com',
                    'www.yahoo.com');
$url = $urlsireland[array_rand($urlsireland)];

if ($CountryCode == 'US'){header('Location: http://www.flags.net/UNST.htm');}
else if ($CountryCode =='DE'){header('Location: http://www.flags.net/GERM.htm');}
else if ($CountryCode =='IE'){header('Location: http://$url');}
else if ($CountryCode =='CA'){header('Location: http://www.flags.net/CANA.htm');}
else {header('Location: http://blackhatworld.com');}
?>
 
Last edited:
There are easier ways ..... Yours is too complicated ..... Just use MaxMind ......
 
Sweet I got it sorted out myself. Delighted. Big thanks to nesterdwarf. I used a slightly modified version of his URL rotate code I found in this thread:

Code:
http://www.blackhatworld.com/blackhat-seo/black-hat-seo/268255-cpa-redirector-2-1-modded-geoip-variable-passing-url-rotation.html
Here is the working code for anyone who wants to redirect people to random URLs based on their geo location.

Code:
<?php

//connect to db
$con = mysql_connect('localhost', 'dbusername', 'password') or die(mysql_error());
 
 
mysql_select_db('dmname', $con);
 
//Get the parameters
if ($_GET["ip"]){
  $ip = mysql_real_escape_string(trim($_GET["ip"]), $con);
} else {
  $ip = getenv('REMOTE_ADDR');
}

 
//Run the IP location query
$ipQuery = mysql_query("SELECT * FROM `ip_group_city` where `ip_start` <= INET_ATON('$ip') order by ip_start desc limit 1;", $con);
$ipData = mysql_fetch_array($ipQuery);
$nbResults = (bool)mysql_num_rows($ipQuery);
                     
$CountryCode = $ipData['country_code'];

//Rotator Code

        if ($CountryCode == US)
            {
            $input = array("http://www.flags.net/UNST.htm",
                            "http://www.url2.com",
                            "http://www.url3.com");
            }
        else if ($CountryCode == CA)
            {
            $input = array("http://www.flags.net/CANA.htm",
                            "http://www.url2.com",
                            "http://www.url3.com");
            }
        else if ($CountryCode == GB)
            {
            $input = array("http://www.flags.net/UNKG.htm",
                            "http://www.url2.com",
                            "http://www.url3.com");
            }
        else if ($CountryCode == NZ)
            {
            $input = array("http://www.flags.net/NWZE.htm",
                            "http://www.url2.com",
                            "http://www.url3.com");
            }
        else if ($CountryCode == AU)
            {
            $input = array("http://www.flags.net/ASTL.htm",
                            "http://www.url2.com",
                            "http://www.url3.com");
            }
        else if ($CountryCode == IE)
            {
            $input = array("http://www.flags.net/IREL.htm",
                            "http://www.url2.com",
                            "http://www.url3.com");
            }
        else {
            $input = array("http://www.blackhatworld.com");
            }
        $rand_keys = array_rand($input, 1);
        $link = $input[$rand_keys] ;
        
        header("Location: $link");
//

?>
 
Last edited:
Someone already asked this question and it wasn't answered. How do I use this script to display the city name to the visitor of a site.

Simple html landing page with text "Attention [city name] residents.. blah blah blah."
 
What do you use the tz info for?
I dont see any reference from the script.
 
Someone already asked this question and it wasn't answered. How do I use this script to display the city name to the visitor of a site.

Simple html landing page with text "Attention [city name] residents.. blah blah blah."

You need php.

PHP:
<?php
echo("Attention " . $City . " residents.");
?>
 
Ah just what I was after, thanks :) +rep:)
 
Back
Top