繁体   English   中英

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

[英]Why won't this simple redirect script work?

我正在尝试在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");
}

?> 

谢谢

我敢打赌这是因为该脚本没有拉您的用户代理。 在该条件的末尾添加一个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';
       }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM