Mobile to Desktop redirection condition doesn't work

I couldn't find anywhere PHP version of redirection depending on screen size so I needed to use combined method echo-ing JS script from PHP but the code I found in one of the answers here doesn't work for some reason. All looks fine but the link keeps going back to mobile version regardless. My desktop version link is (sorry can't display tags here):

href="http://www.webaddress.co.uk/?v=desktop" data-ajax="false" rel="external"

And at the top of my index.php desktop version I have:

<?php session_start();

if (isset($_GET['v']) && $_GET['v'] == 'desktop') {
$_SESSION['v'] == 'desktop';
}

if (!isset($_SESSION['v']) || (isset($_SESSION['v']) && $_SESSION['v'] != 'desktop')) {
   echo "<script> if (window.screen.width < 1000) {window.location = '/mobile'; }</script>";
}
?>

For some reason the redirection finds the second condition always valid.

Answers


In your first if statement I'm pretty sure you want to set $_SESSION['v'] and not compare it against 'desktop'.


<?php session_start();

if (isset($_GET['v']){
  if ($_GET['v'] == 'desktop') {
     $_SESSION['v'] = 'desktop';
  }
  if ($_GET['v'] == 'mobile') {
     $_SESSION['v'] = 'mobile';
  }

}

if (!isset($_SESSION['v'])) {
   echo "<script> if (window.screen.width < 1000) {window.location = '/?v=mobile'; } else {window.location = '/?v=desktop' }</script>";
}
?>

Need Your Help

need to create a summary of a large switch statement in C#

c# switch-statement summary

Alright, i dont know how to explain it well.. but i have a switch statement,