嘿大家我正在使用我在另一个问题中找到的代码,该代码表明它已正确回答并正常工作。虽然这对我不起作用,但我已在多台设备上试用过它。
可在此处找到完整代码(这是代码库):https://raw.githubusercontent.com/serbanghita/Mobile-Detect/master/Mobile_Detect.php
问题在于:Best way to redirect single php page for mobile devices with PHP/Javascript
我的代码是:
<?php require('includes/mobileRedirect.php'); ?>
<?php
$detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
header('Location: http://m.jollyrogerpcs.com/');
exit;
}
?>
问题似乎在“标题”区域附近。如果我用echo('mobile')替换标题;它有效,但无论我做什么,我都无法通过手机重定向。
编辑:通过在DOCTYPE之前移动代码解决了问题。
答案 0 :(得分:0)
将此代码移至DOCTYPE之前,它就像魅力一样。
<?php require('includes/mobileRedirect.php');
$detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
header('Location: http://m.jollyrogerpcs.com/');
}
?>