dongmo9996 2016-07-19 14:26
浏览 120

php重定向无法正常工作

I got a simple redirect on my homepage, which reacts to the user being on a smartphone or tablett. The Class is working and gives back a true when the side is opened on a smartphone.

Therefore if i write an echo in the if-statement it gets echoed. But the redirection doesn't work and i can't make a sense of it. Anyone any clue what i missed here?

include ('includes/Mobiledetecter.php');                 
$detect = new Mobiledetecter;                                  
                                 //
if($detect->isMobile() or $detect->isTablet()) {           
    header('Location: http://www.example.com/');
} 
  • 写回答

4条回答 默认 最新

  • duanlan3598 2016-07-19 14:30
    关注

    Exit immediately after setting the header if there is nothing else to do:

    if($detect->isMobile() or $detect->isTablet()) {           
        header('Location: http://www.example.com/');
        exit;
    } 
    

    Also consider that headers only work if you haven't already sent output to the browser, either explicitly (eg: echo) or implicitly (eg: by having anything including blank space before the <?php tag that contains this header)

    评论

报告相同问题?

悬赏问题

  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计