0

我已经有了通过检测用户使用的设备将用户重定向到移动网站的代码。重要提示:这意味着移动网站和完整网站具有相同的 URL:http ://example.com 。没有 m.example.com 或 mobile.example.com --- 只有 example.com

function _check(){

    $agent = $_SERVER["HTTP_USER_AGENT"]; 

    $mobile = false;
    $agents = array("Alcatel", "Blackberry", "HTC",  "LG", "Motorola", "Nokia", "Palm", "Samsung", "SonyEricsson", "ZTE", "Mobile", "iPhone", "iPod", "Mini", "Playstation", "DoCoMo", "Benq", "Vodafone", "Sharp", "Kindle", "Nexus", "Windows Phone");
    foreach($agents as $a){

        if(stripos($agent, $a) !== false){                 
            return $a;
        }

    }
    return $mobile;
}

现在我想创建一个链接,一旦单击该链接,就会将他的 $mobile 变量设置为 false,以便显示整个站点而不是移动站点(因为两者具有相同的 URL)。

有谁知道如何检测何时单击链接,将 $mobile 变量设置为 false?

提前致谢。

4

1 回答 1

0

Use a cookie - in your test code, first check to see if the cookie is set, and then check user agents. If the cookie is set, set $mobile to false and don't do any other checks - otherwise, fall through to checking user agents.

When your user clicks on the "view full site" link, set the cookie for them so that your code knows to skip checking their user agent.

于 2012-07-09T20:40:05.283 回答