[英]Redirection is working in opera but not in fennec and other mobile browsers?
我有一个移动网站,并且正在将移动用户从主网站重定向到移动网站。 但是我在移动网站上也提供了一些选择,如果某些移动用户想要访问主网站,他可以。 为了解决这个问题,我在主网站上编写了此代码
if (is_mobile()== true) //if user is browsing from mobile
{
$main_website_url= 'http://localhost/www/redsignal/'; // main website URL
$mobilesite_url = 'http://localhost/www/redsignal-mobile/'; //mobile website URL
$mobilesite_url_length = strlen($mobilesite_url);
$referring_path_url = substr($_SERVER['HTTP_REFERER'], 0 , $mobilesite_url_length);
if ($referring_path_url == $mobilesite_url) //This if condition checks that if the mobile user is coming from my mobile website or not
{
header("Location:".$main_website_url); // if he is coming from mobile he will be redirected to main website
}
else
{
header("Location:".$mobilesite_url); // if not than he will be redirected to mobile website
}
}
您需要使用另一个变量来区分是否要在单击移动站点中的访问原始站点时强制显示原始站点。 为此,您可以传递GET变量,例如
http:// localhost / www / redsignal /?force_show_original = 1
然后在您的代码中更改此
if (is_mobile()== true)
至
if (is_mobile()== true || $GET["force_show_original"] == true)
让我知道它是否有效
更新
使用以下代码重定向网站
if (is_mobile()== true || $GET["force_show_original"] == false) {
//redirect to mobile site
}
else if(is_mobile()== true || $GET["force_show_original"] == true) {
// redirect to original site
}
else {
// redirect to original site
}
如果标题不起作用,则可以使用javascript进行重定向,例如
echo "<script type='text/javascript'> document.location.href='$main_website_url'</script> ";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.