[英]How to stay on Desktop site when redirected from mobile (wordpress)
On my desktop site, I'm using a redirect script "detectmobilebrowser.js" (from detectmobilebrowsers.com) that's working great to redirect mobile users to my mobile site. 在我的桌面站点上,我正在使用重定向脚本“ detectmobilebrowser.js”(来自detectmobilebrowsers.com),该脚本可以很好地将移动用户重定向到我的移动站点。 This code is loaded in the header.php file.
此代码已加载到header.php文件中。
On my mobile site i have a link pointing back to my Desktop site with a URL Parameter 'nomobile'. 在我的移动网站上,我有一个链接指向我的桌面网站,其URL参数为“ nomobile”。 on the desktop site i have the following code (below) that detects the url parameter and does nothing if it exists, or redirects to the mobile site using the .js detection file if the parameter doesn't exist.
在桌面站点上,我具有以下代码(如下),该代码可以检测url参数,如果存在则不执行任何操作,或者如果参数不存在,则使用.js检测文件重定向到移动网站。
My problem is once a user clicks on any link from the home page, i lose the url parameter and the mobile user is redirected back to the mobile site. 我的问题是,一旦用户单击主页上的任何链接,我就会丢失url参数,并且移动用户将被重定向回移动站点。 How can I keep the mobile user on the desktop site without changing hundreds of links on my page to include the url parameter?
如何在不更改页面上的数百个链接以包含url参数的情况下,将移动用户保留在桌面站点上?
<?php
if(isset($_GET['nomobile'])){
echo "";
} else {
echo "<script src='http://mywebsite.com/detectmobilebrowser.js'></script>";
}
?>
Don't use a URL parameter to set. 不要使用URL参数进行设置。 Try using a session variable instead.
尝试改用会话变量。
To set the session variable 设置会话变量
$_SESSION['nomobile']=true;
To check if the session is set 检查会话是否已设置
if(isset($_SESSION['nomobile'])) {
// do stuff
}
Alternatively, you could also use cookies instead of session variables, and that should produce the same results. 另外,您也可以使用cookie代替会话变量,这将产生相同的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.