Posts Tagged ‘Geolocation’

How To Display Content Based on Ip (Geolocation)

Let me show you how to do Geolocation  Content based on ip address !(with php and mysql)
first you need a database eg make  a database  call it what ever you want now you will need to Get A Database of ip 80% world wide accuriate  Click Here to download ( ip2nation )

Then insert import the sql (taken from ip2nation but small changes)

note Go to http://ip2nation.com/ip2nation/Sample_Scripts
and Get it …the bottom of code is different examples of use

<?php
////////////////dot use this get it from ip2nation.com
	$server   = ''; // MySQL hostname
	$username = ''; // MySQL username
	$password = ''; // MySQL password
	$dbname   = ''; // MySQL db name
$table = "ip2nation";
	$db = mysql_connect($server, $username, $password) or die(mysql_error());
	      mysql_select_db($dbname) or die(mysql_error());
	$sql = 'SELECT `country`FROM
	            `$table`
	        WHERE
	            `ip` < INET_ATON("'.$_SERVER['REMOTE_ADDR'].'")
	        ORDER BY
	            `ip` DESC
	        LIMIT 0,1';

	list($country) = mysql_fetch_row(mysql_query($sql));
// use a switch statement for redirect
	switch ($country) {
		case 'ca':
			// Get the Canadians to a canadians site
			header('Location: http://www.yoursite.ca/');
			exit;
		case 'us':
			// And redirect US visitors to your .com
			header('Location: http://www.yoursite.com/');
	exit;
		default:
			// The rest of the world can go to defult
			header('Location: http://www.yoursite.com.au/');
			exit;
	}
//Get The Basic Idea include a file
if($country = 'ca'){
include ("canada.php");
}else{
include ("USA.php");
}
// Display an image
switch ($country) {
case 'ca':
// show canada flag

echo"<img src='images/canada.jpg' />";
exit;
case 'us':
// show us flag
echo"<img src='images/usa.jpg' />";
exit;
default:// the default flag
echo"<img src='images/australia.jpg' />";');
}
?>

try it
http://taggartjensen.com/ip
Have Fun this demo is for  Australia, Canada, Usa

Subscription

Fill out the form below to signup to my newsletter and You Can Get New Cool free Scripts , advice ...ect

Our strict privacy policy keeps your email address 100% safe & secure.



























Ads1



Designed by Taggart Jensen .