我正在尝试使用此脚本在我的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");
}
?>
由于
答案 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';
}