PHP移动重定向不起作用
我有这个代码,我试图重定向移动用户到移动优化页面和桌面用户到桌面页面PHP移动重定向不起作用,php,android,redirect,mobile,Php,Android,Redirect,Mobile,我有这个代码,我试图重定向移动用户到移动优化页面和桌面用户到桌面页面 <?php if(stristr($_SERVER['HTTP_USER_AGENT'],'iPad')|| stristr($_SERVER['HTTP_USER_AGENT'],'iPhone')|| stristr($_SERVER['HTTP_USER_AGENT'],'iPod')|| stristr($_SERVER['HTTP_USER_AGENT'],
<?php if(stristr($_SERVER['HTTP_USER_AGENT'],'iPad')||
stristr($_SERVER['HTTP_USER_AGENT'],'iPhone')||
stristr($_SERVER['HTTP_USER_AGENT'],'iPod')||
stristr($_SERVER['HTTP_USER_AGENT'],'Android')){ ?>
mobile-page.com
<?php } else { ?>
dekstop-page.com
<?php } ?>
现在,我试图通过执行elseif语句来进一步重定向移动Android和Iphone用户,但我发现了一个错误
<?php if(stristr($_SERVER['HTTP_USER_AGENT'],'iPad')||
stristr($_SERVER['HTTP_USER_AGENT'],'iPhone')||
stristr($_SERVER['HTTP_USER_AGENT'],'iPod')){ ?>
iphone-page.com
<?php } elseif(stristr($_SERVER['HTTP_USER_AGENT'],'Android')){ ?>
android-page.com
<?php } else { ?>
dekstop-page.com
<?php } ?>
有人能帮我找出哪里出错了吗?试试这个
<?php
if(stristr($_SERVER['HTTP_USER_AGENT'],'iPad')||
stristr($_SERVER['HTTP_USER_AGENT'],'iPhone')||
stristr($_SERVER['HTTP_USER_AGENT'],'iPod')||
stristr($_SERVER['HTTP_USER_AGENT'],'Android'))
{
header( 'Location: mobilepage.html') ; //forward to mobile page
} else {
header( 'Location: desktoppage.html') ; //forward to desktop page
}
?>
@whyceewhite@Subin Thomas@rahul它实际上工作得非常好!我的服务器出现语法错误,因为我忘记了代码中的一个花括号。这里的代码没有问题。我道歉
I used <?php else { ?> instead of <?php } else { ?>
如果需要自动重定向,请使用标题。能否提供收到的错误,以便我们更好地确定您遇到的问题?但我想将AndRoid用户重定向到AndRoidPage.com,Iphone用户重定向到iphonepage.com,PC用户重定向到dekstoppage.com更改pagename dude。。例如:“位置:blabla.html”
I used <?php else { ?> instead of <?php } else { ?>