Page 1 of 1

Switching off Mobile Site.

Posted: Fri Aug 17, 2012 6:22 am
by FrederickGeek8
I am trying to setup a link that turns off mobile site on mobile devices (I am using this) using cookies but it does not seem to be working... Here is my code

Mobile website
<?php
if(isset($_GET['normal_site'])){
    setcookie('mobile_site', 'off', time() + 604800);
    header('Location: http://nerd.net');
}
?>
<!DOCTYPE html>
<html lang='en'>
  <head>
    <meta charset='utf-8'>
    <title>Mobile Site | NERD.net</title>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <meta name='description' content=''>
    <meta name='author' content='Fred Morlock'>

    <!-- Le HTML5 shim, for IE6-8 support of HTML5 elements -->
    <!--[if lt IE 9]>
      <script src='http://html5shim.googlecode.com/svn/tru ... '></script>
    <![endif]-->
    <script type='text/javascript'>

  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-33874985-1']);
  _gaq.push(['_setDomainName', 'nerd.net']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();

</script>
</head>
<body>
<h1>This is going to be the mobile site. </h1>
<footer><a href='index.php?normal_site=1'>Use Normal Site</a></footer>
</body>
</html>
init.inc.php (Lots of code. Only posting what is important)
$detect = new Mobile_Detect();
if(isset($_COOKIE['mobile_site'])){
    if((($_COOKIE['mobile_site']) === 'off')){
        // do nothing
    }
}else{
    if ($detect->isMobile()) {
        header('Location: http://m.nerd.net');
    }
}

Re: Switching off Mobile Site.

Posted: Fri Aug 17, 2012 11:02 am
by Helx
Well, your cookies are fine.

Image
Though, I would probably say that you should put the cookie for the entire domain (nerd.net is the top-level domain, and should be assigned to it)

And I'm not at all sure... But give this a try:
    $detect = new Mobile_Detect();
    if(isset($_COOKIE['mobile_site'])){
        if($_COOKIE['mobile_site'] == 'off'){
            // do nothing
        }else{
        if ($detect->isMobile()) {
            header('Location: http://m.nerd.net');
        }
    }

Re: Switching off Mobile Site.

Posted: Fri Aug 17, 2012 2:30 pm
by FrederickGeek8
That didn't help and I have no idea how to assign cookies to the top-level domain

EDIT: Nevermind I got it using
setcookie('mobile_site', 'off', time() + 604800, '/', 'nerd.net');