根据变量值重定向到不同的页面

时间:2017-11-21 10:51:52

标签: php redirect

我正在使用Geoplugin将访客城市和标题重定向到不同的页面,但我得到了

  

警告:无法修改标头信息 - 已发送的标头

并且它不会重定向任何页面

请帮我解决此问题

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;

} ?&GT;

1 个答案:

答案 0 :(得分:1)

您收到错误是因为您在标题

之前回显了这些错误
  echo "City: ".$city."<br>";
  echo "Region: ".$region."<br>";
  echo "Country: ".$country."<br>";

header

之前不应该有任何输出