将网站重定向到移动网站以及从移动设备重定向到桌面? [英] Redirect website to mobile site and from mobile to desktop?

查看:109
本文介绍了将网站重定向到移动网站以及从移动设备重定向到桌面?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果用户希望从移动设备转到桌面网站,该如何处理?

How can I handle the situation if the user wants from mobile to go to desktop site?

我正在使用该库来重定向到移动设备,以及如何创建重定向.下面的代码是我正在使用mobile_detect.php库:

I am using this library for redirect to mobile, and how to create a redirect. The code below is that I am using mobile_detect.php library:

require_once 'controller/Mobile_Detect.php';
$detect = new Mobile_Detect;

// Any mobile device (phones or tablets).
if ( !$detect->isMobile() ) {

   //the link to mobile site

}

但是反之亦然吗?

感谢您的帮助

推荐答案

<a href="self.php?desktop=1">Switch to desktop</a>

<?php
if(!isset($_SESSION['desktop'])) {
    $_SESSION['desktop'] = false;
}

if(isset($_GET['desktop']) && $_GET['desktop'] == 1) {
    $_SESSION['desktop'] = true;
}

if(!$_SESSION['desktop']) {
    if ( !$detect->isMobile() ) {

       //the link to mobile site

    }

}

在移动网站上,您可以通过传递get参数desktop=1来使人们有机会切换到桌面(完成重定向的页面).通常,如果未传递参数,并且未设置会话,则为false.在$ _SESSION ['desktop']的错误值上,您继续执行脚本,以便将其重定向到移动设备.但是一旦参数通过,它将会话更改为true,并且您的阻止将不会执行,因此该站点的正常(桌面)内容将可见

On your mobile site you give the opportunity to people to switch to desktop (the page where the redirect is done) with passing a get parameter of desktop=1. Normally, if the parameter is not passed, and if the session is not set, it's false. On false value of $_SESSION['desktop'], you continue your script so it redirects to mobile. But once the param is passed, it changes the session to true, and you block will not be executed, so the normal (desktop) content of the site will be visible

这篇关于将网站重定向到移动网站以及从移动设备重定向到桌面?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆