为什么这个简单的重定向脚本不起作用?

时间:2016-06-17 13:57:30

标签: php

我正在尝试使用此脚本在我的index.php页面的顶部检测用户正在使用哪个平台,但是在我的计算机浏览器上访问该页面时它不会重定向(它应该重定向到google.com )

<?php

//Detect special conditions devices
$iPod    = stripos($_SERVER['HTTP_USER_AGENT'],"iPod");
$iPhone  = stripos($_SERVER['HTTP_USER_AGENT'],"iPhone");
$iPad    = stripos($_SERVER['HTTP_USER_AGENT'],"iPad");
$Android = stripos($_SERVER['HTTP_USER_AGENT'],"Android");
$webOS   = stripos($_SERVER['HTTP_USER_AGENT'],"webOS");

 //do something with this information
if( $iPod || $iPhone ){
header("Location: http://example.com/myOtherPage.php");
 }else if($iPad){
//browser reported as an iPad -- do something here
}else if($Android){
header("Location: http://example.com/myOtherPage.php");
}else if($webOS){
header("Location: http://google.com");
}

?> 

由于

1 个答案:

答案 0 :(得分:0)

我敢打赌,因为该脚本不会拉你的用户代理。在该条件的末尾添加else。因为它不属于任何类别,所以它没有被重定向

  <?php
       if( $iPod || $iPhone ){
           header("Location: http://example.com/myOtherPage.php");
       }else if($iPad){
           //browser reported as an iPad -- do something here
       }else if($Android){
           header("Location: http://example.com/myOtherPage.php");
       }else if($webOS){
           header("Location: http://google.com");
       }else{
          echo 'User agent not detected';
       }
相关问题