简体   繁体   中英

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

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> ";

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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