dongxing2015 2017-11-21 10:51
浏览 41
已采纳

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

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>
  • 写回答

1条回答 默认 最新

  • dongxue9997 2017-11-21 10:53
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法