Jump to content

Is It Possible to Present Different Content to People in Different Countries?


Fluoresce

Recommended Posts

Hi, guys.

 

I want to present different ads to visitors in different countries.  For example, if a visitor is in Australia, I want him/her to see a different ad from, say, a visitor from the UK. Can this kind of thing be done with PHP? If so, will installing such a code slow down my site?

 

Any help will be appreciated very much.

There is a simple way to do it, without installing anything but it can be slow on occassions.

 

Look at this

<?PHP

function getLocation($string,$oTag,$cTag) {
  // Get position of openingTag
  $start = strpos($string, $oTag);                   
  // Get position of endingTag        
  $end   = strpos($string, $cTag, ($start + strlen($oTag))); 
  // Remove everything before openingTag
  $start = ($start + strlen($oTag));      
  // Remove everything after endingTag                   
  $end   = ($end - $start);         
  // Return the location of the IP                         
  return substr($string, $start, $end);                      
}

// Get the visitors IP Address
$ipAddress  = $_SERVER['REMOTE_ADDR'];

// Look up the visitors IP Address for location
$ipLocation = file_get_contents('http://api.hostip.info/get_html.php?ip='.$ipAddress.'');

// Filter returned string to get the country of the IP
$ipLocation = getLocation($ipLocation,'(',')');

// Display the location of the visitors IP
echo $ipLocation;

?>

 

Thanks should do it for, but it is not 100% correct all of the time.

 

Regards, Paul.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.