We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 33988
    • 110 Posts
    Well there are two reasons.
    First, the mobile site is a limited site and only has about 3% of the info that the full site has.
    Second, the redirection code may direct certain mobile devices incorrectly, in which case we would like to allow the user to go to the main site, since they can judge that their device can handle such.
      Sal Sodano
      President & Co-Founder of SkyToaster
      My Website Salscode.
      • 33988
      • 110 Posts
      Does anyone know how I can add a php session to Breezer’s code. That way, when the user switches to the main site, it will not redirect back to the mobile site until the session for that user ends? Below is the code we are using.
      <?php
      session_start();
      $_SESSION['classic'] = 1;
      ?>
      

      Redirect Code
      <?php
      /*     Mobile browser redirect
             original code: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers
             [!Mobile_redirect? &mID=`1`!]
      */
      // set the document ID of the mobile page
      $mid = isset($mID) ? $mID : "mobile";
      
      
       if(isset($_SESSION['views'])){
          $_SESSION['views'] == 1;
      } else {
                      if(isset($_SERVER["HTTP_X_WAP_PROFILE"]) || preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) {
                 header("Location: ".$mid."");
                      }
      
                      if(isset($_SERVER["HTTP_USER_AGENT"])){
              if(preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) { return false; }
              $uamatches = array("midp", "j2me", "avantg", "iphone", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto");
              foreach($uamatches as $uastring){
              if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) //return true;
                 header("Location: ".$mid."");
              }
                      }
      }
      ?>
      
        Sal Sodano
        President & Co-Founder of SkyToaster
        My Website Salscode.
        • 4041
        • 788 Posts
        Try this one, it checks for a $_GET value or a $_SESSION value first, if none found it should redirect... then a link in the mobile site back to the main with views=1 added to the url. Untested, but in theory it should work I think. smiley

        <?php
        /*     Mobile browser redirect
               original code: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers
               [!Mobile_redirect? &mID=`1`!]
               
               link back to main page:
               <a href="http://yourmainsite.com?views=1">Link Back to Main site</a>
        */
        // set the document ID of the mobile page
        $mid = isset($mID) ? $mID : "mobile";
        
        
         if(isset($_GET['views']) || $_SESSION['views'] =="1"){
            $_SESSION['views'] = 1;
        } else {
                        if(isset($_SERVER["HTTP_X_WAP_PROFILE"]) || preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) {
                   header("Location: ".$mid."");
                        }
        
                        if(isset($_SERVER["HTTP_USER_AGENT"])){
                if(preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) { return false; }
                $uamatches = array("midp", "j2me", "avantg", "iphone", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto");
                foreach($uamatches as $uastring){
                if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) //return true;
                   header("Location: ".$mid."");
                }
                        }
        }
        ?>
          xforum
          http://frsbuilders.net (under construction) forum for evolution
          • 1343 ☆ A M B ☆
          • 2,213 Posts
          Hey Breezer,

          Thank you for the code it worked like a charm! I don’t know why it wasn’t working before, but in any case that was just what the doctor ordered.

          If you don’t have any objections I will add the code to the repository later this week after I do some further testing.

          Thanks again,
          AMDbuilder
            Patrick | Server Wrangler
            About Me: Website | Tweets |  MODX Hosting
            • 4041
            • 788 Posts
            Glad it worked, and feel free to do whatever you want with it but please leave the original code link in there, all I did was snippetize it smiley
              xforum
              http://frsbuilders.net (under construction) forum for evolution
              • 454
              • 2 Posts
              Thanks all for this very helpful posting...one real newboy question.....

              Where in the code snippet do i actually tell it which page to get directed to? ie what line...

              example please...say go to page "mobile.htm" wher ein the code do i say go to that page?


              many thanks for answering a most basic question....

              addy
                • 1343 ☆ A M B ☆
                • 2,213 Posts
                Hello,

                You want to change this line here:
                $mid = isset($mID) ? $mID : "mobile";


                Replace mobile with the alias for your mobile page. Originally this was setup to use the page ID (some of the first code examples), but the page ID didn’t work for me so I just modified it some so it would accept the page alias. If someone knows how to get the page ID working that would be nicer than my method.

                Enjoy
                AMDbuilder
                  Patrick | Server Wrangler
                  About Me: Website | Tweets |  MODX Hosting
                  • 454
                  • 2 Posts
                  Many thanks, that helps me a great deal..... smiley
                    • 4041
                    • 788 Posts
                    Touching base on this topic again after reading another post interested in this feature, here is another version which allows either a MODx id or a url to be passed to the snippet. Also the issue raised by AMDbuilder where an id wouldn’t work has been fixed I think smiley.

                    I don’t have mobile web browser testing capabilities, so if someone would give this a try it would be appreciated.

                    <?php
                    /*     Mobile_redirect
                           11/24/09   10:31 am est
                           
                           original code: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers
                           usage: call in the top of your template
                           [!Mobile_redirect? &mID=`1`!]
                           [!Mobile_redirect? &url=`http://redirectdomain.com`!]
                           
                           link back to main page:
                           add &views=1 to the link
                           ex: <a href="http://yourmainsite.com?views=1">Link Back to Main site</a>
                    */
                    
                    // set the MODx document ID of the mobile page
                    $mid = isset($mID) ? $mID : "1";
                    
                    // set the url you want to redirect to
                    // http://domain.com   or   http://sub.domain.com
                    $url = isset($url) ? $url : '';
                    
                    if(isset($_GET['views']) || $_SESSION['views'] =='1'){
                        $_SESSION['views'] = 1;
                        
                    }else{
                            if(isset($_SERVER["HTTP_X_WAP_PROFILE"]) || preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) {
                                if($mid =="" && $url !=""){
                                    header("Location: ".$url."");
                                }else{
                                    $goto = $modx->makeUrl($mid);
                                    $modx->sendRedirect($goto);
                                }
                            }
                    
                            if(isset($_SERVER["HTTP_USER_AGENT"])){
                                if(preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) { return false; }
                                $uamatches = array("midp", "j2me", "avantg", "iphone", "docomo", "novarra", "palmos", "palmsource", "240x320", "opwv", "chtml", "pda", "windows\ ce", "mmp\/", "blackberry", "mib\/", "symbian", "wireless", "nokia", "hand", "mobi", "phone", "cdm", "up\.b", "audio", "SIE\-", "SEC\-", "samsung", "HTC", "mot\-", "mitsu", "sagem", "sony", "alcatel", "lg", "erics", "vx", "NEC", "philips", "mmm", "xx", "panasonic", "sharp", "wap", "sch", "rover", "pocket", "benq", "java", "pt", "pg", "vox", "amoi", "bird", "compal", "kg", "voda", "sany", "kdd", "dbt", "sendo", "sgh", "gradi", "jb", "\d\d\di", "moto");
                                foreach($uamatches as $uastring){
                                    if(preg_match("/".$uastring."/i",$_SERVER["HTTP_USER_AGENT"])) //return true;
                                        if($mid =="" && $url !=""){
                                            header("Location: ".$url."");
                                        }else{
                                            $goto = $modx->makeUrl($mid);
                                            $modx->sendRedirect($goto);
                                        }
                                    }
                            }
                    }
                    ?>
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution
                      • 4455
                      • 76 Posts
                      Hey Breezer, just tested and all looks to be working great on my nokia.

                      Cheers
                      Free