Classic View/Mobile View Switch?

泄露秘密 提交于 2019-12-03 17:38:10

First, such things i would not do this with Javascript/Query, cause what is if the user has not activate js? It is better to do this server-side.

Something like this:

$mobile = array("IPHONE", "IPAD");
$flagMobileVersion = false;
if($_SESSION['version']!="mobile"){ //happens only at first visit
for($i=0;$i<=count($mobile)-1;$i++){
    if(!strrpos(strtoupper($_SERVER['HTTP_USER_AGENT']), $mobile[$i]))
    {
        $flagMobileVersion = true;
        break;
    }
}

if($flagMobileVersion) {
$_SESSION['version'] = "mobile";
Header("www.mydomain.net/mobile"); //on first Visit
}
Michael Martin-Smucker

Would something like this work:

All you'd have to do differently is wrap the window.location redirection code on the main page inside an if statement that makes sure the noredirect flag isn't set to true. The only challenge would be isolating the noredirect query string, but this Stack Overflow question might help.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!