This question already has an answer here:
- How to fix “Headers already sent” error in PHP 11 answers
- Headers already sent… where? [duplicate] 3 answers
- PHP headers already sent [duplicate] 4 answers
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>