How to redirect website to desktop version?

1

My site has two versions: Desktop and Mobile.

When I access the mobile "www.mysite.com", I am redirected to the mobile version: "m.mysite.com".

To do this, I'm using this very cool project called Mobile Detect

So far so good.

The site in the Mobile version has a button to access the Desktop version "Switch to Desktop version". And that's where the problem comes from.

When I click the button to access the Desktop version, I am redirected from "m.mysite.com" to "www.mysite.com". The page loads, and the Mobile Detect script is loaded again and I'm redirected to "m.mysite.com" again. That is, it goes into a loop.

For a better example:

---> "Switch to Desktop" button is clicked

--- > The page is redirected to "www.mysite.com"; --- > The "www" page loads; --- > As I'm on the mobile and I'm on the "www.", The Mobile Detect script is loaded again and I go back to "m.myusite.com";

Site code version Desktop :

<?php
  require_once 'Mobile_Detect.php';
  $detect = new Mobile_Detect;
?>
<!DOCTYPE html>
<html>
 <head>
<meta charset="utf8">
  <?php if( $detect->isMobile() ) : ?>

    <script type="text/javascript">
         window.location.href = "http://m.meusite.com.br";  
    </script>

  <?php endif ?>

 </head>
<body style="padding: 0; margin: 0">

<div class="wrapper" style="height: 100vh; display: flex; justify-content: center; align-items: center; flex-direction: column">
  <h1>VERSÃO DESKTOP</h1>      
</div>
 </body>
</html>

Mobile site version code Mobile :

<!DOCTYPE html>
<html>
<head></head>
<body style="padding: 0; margin: 0">
    <div class="wrapper" style="height: 100vh; display: flex; justify-content: center; align-items: center; flex-direction: column">
      <h1>VERSÃO MOBILE</h1>
      <?php    
          require_once "../Mobile_Detect.php";
          $detect = New Mobile_Detect;

           if( $detect->isMobile() && (!isset($_GET['force_desktop']) || $_GET['force_desktop'] == 'false')) : ?>
               <a href="http://www.meusite.com.br&force_desktop=true">REDIRECIONAR PARA DESKTOP</a>
            <?php endif; ?>
    </div>
</body>
</html>

Thinking about a logic of forcing the page to stay in the desktop version when I'm on the phone, I'm using that code inside the button that redirects to the desktop:

 if( $detect->isMobile() && (!isset($_GET['force_desktop']) || $_GET['force_desktop'] == 'false')) : ?>
     <a href="http://www.meusite.com.br&force_desktop=true?">REDIRECIONAR PARA DESKTOP</a>
 <?php endif; ?>

However, it gives page error not found. I think I'm missing the parameter passing the URL.

How can I resolve this? How can I force redirection to the Desktop version when I'm on my cell phone?

    
asked by anonymous 21.10.2016 / 15:13

1 answer

-1

You can check if the value of your GET exists, if it exists the verification of the device is not done.

<?php
  require_once 'Mobile_Detect.php';
  $detect = new Mobile_Detect;
?>
<!DOCTYPE html>
<html>
 <head>
<meta charset="utf8">

  <?php if( !isset($_GET['force_desktop']) && empty($_GET['force_desktop'])) : ?>

  <?php if( $detect->isMobile() ) : ?>

    <script type="text/javascript">
         window.location.href = "http://m.meusite.com.br";  
    </script>

  <?php endif ?>
  <?php endif ?>
  <?php var_dump($_GET); ?>
 </head>
<body style="padding: 0; margin: 0">

<div class="wrapper" style="height: 100vh; display: flex; justify-content: center; align-items: center; flex-direction: column">
  <h1>VERSÃO DESKTOP</h1>     
</div>
 </body>
</html>
    
21.10.2016 / 16:13