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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.