Hello everyone, I need help with installing a geo redirect script on my website, what I need to do is redirect US traffic to an US page, UK to a UK page, and so forth…? Im not sure how to modify the code so to have work for me.
The php code is this one:
[code=php]<?php
require_once(‘geoip.inc’);
$gi = geoip_open(‘GeoIP.dat’, GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER[‘REMOTE_ADDR’]);
geoip_close($gi);
$my_countries = array(‘us’, ‘ca’, ‘gb’, ‘fr’, ‘de’, ‘nl’);
if (!in_array(strtolower($country), $my_countries))
{
header(‘Location: http://www.”ALL”TRAFFICURLGOESHERE.whatever’);
}
else
{
header(‘Location: http://www.”SELECTEDCOUNTRIES”URLGOESHERE.whatever’);
}
?>
Ive inserted the code and when I go to the domain I see this message:
Warning: Cannot modify header information – headers already sent by (output started at /home/public_html/mydomain.com – Copy.php:7) in /home/public_html/mydomain.com/ on line 21
Thats how Ive inserted the code:
[code=php]<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<title>My Title</title>
<?php
require_once(‘geoip.inc’);
$gi = geoip_open(‘GeoIP.dat’, GEOIP_MEMORY_CACHE);
$country = geoip_country_code_by_addr($gi, $_SERVER[‘REMOTE_ADDR’]);
geoip_close($gi);
$my_countries = array(‘us’);
if (!in_array(strtolower($country), $my_countries))
{
header(‘Location: US URL goes here’);
}
else
{
header(‘Location: other URLs goes here’);
}
?>
</head>
</body>
</html>
Thank you in advance!