简体   繁体   English

重定向在Opera中有效,但在fennec和其他移动浏览器中无效吗?

[英]Redirection is working in opera but not in fennec and other mobile browsers?

I have a mobile website and I am redirecting mobile users from main website to mobile website. 我有一个移动网站,并且正在将移动用户从主网站重定向到移动网站。 But I have also given option on my mobile website that if some mobile user want to visit the main website he can. 但是我在移动网站上也提供了一些选择,如果某些移动用户想要访问主网站,他可以。 To solve the problem I wrote this code on my main website 为了解决这个问题,我在主网站上编写了此代码

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     
    }


}

You need to use another variable in order to distinguish whether you want to force show original site when click on visit original site in mobile site. 您需要使用另一个变量来区分是否要在单击移动站点中的访问原始站点时强制显示原始站点。 For this u can pass GET variable for eg 为此,您可以传递GET变量,例如

http://localhost/www/redsignal/?force_show_original=1 http:// localhost / www / redsignal /?force_show_original = 1

Then in your code you change this 然后在您的代码中更改此

if (is_mobile()== true)

to

if (is_mobile()== true || $GET["force_show_original"] == true)

let me know whether it worked 让我知道它是否有效

UPDATE 更新

Use following code to redirect site 使用以下代码重定向网站

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM