This question already has an answer here:
I am using Geoplugin to get visitor city and header to Redirect to different page according to it but I got
Warning: Cannot modify header information - headers already sent
and Its not redirecting any page
please help me to resolve this
Code I Tried:
<?php
$user_ip = getenv('REMOTE_ADDR');
$geo = unserialize(file_get_contents("http://www.geoplugin.net/php.gp?
ip=$user_ip"));
$city = $geo["geoplugin_city"];
$region = $geo["geoplugin_regionName"];
$country = $geo["geoplugin_countryName"];
echo "City: ".$city."<br>";
echo "Region: ".$region."<br>";
echo "Country: ".$country."<br>";
switch ($city) {
case "Vijayawada":
header("Location: http://www.website.com/test/andhra.php");
break;
case "Bangalore":
header("Location: http://www.website.com/test/bglr.php");
break;
default:header("Location: http://www.website.com/test/index.php");
exit;
} ?>
</div>
You are getting error because you are echoing these before header
echo "City: ".$city."<br>";
echo "Region: ".$region."<br>";
echo "Country: ".$country."<br>";
There should not be any output before header