简体   繁体   中英

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. This code is loaded in the header.php file.

On my mobile site i have a link pointing back to my Desktop site with a URL Parameter '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.

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. How can I keep the mobile user on the desktop site without changing hundreds of links on my page to include the url parameter?

    <?php

    if(isset($_GET['nomobile'])){
       echo "";
    } else {
       echo "<script src='http://mywebsite.com/detectmobilebrowser.js'></script>";
    }

    ?>

Don't use a URL parameter to set. 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.

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