We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1343 ☆ A M B ☆
    • 2,213 Posts
    Hello,

    I am in the process of setting up a mobile website and want to do automatic redirection. Does anyone have a suggestion on the best way to redirect mobile clients to the mobile site? The catch is I want to allow them to still access the full site if desired and everything I have found so far is one way only.

    Thanks,
    AMDbuilder
      Patrick | Server Wrangler
      About Me: Website | Tweets |  MODX Hosting
      • 11055 ☆ A M B ☆
      • 3,112 Posts
      1. The easiest way is by making another subdomain (eg: m.yourwebsite.com).
      2. You can read the browser type. But it means you should try all mobile browsers (like Opera Mini).
      3. I had an experience on making a webbased mobile database interface (with PDA). The language was plain html/php. No CSS and/or JS.
      4. Nowadays, mobiles get more intelligent. Especially with Windows based system. The applications become as same as desktop computer’s apps. With this kind of mobile, we might not have to make different one.

      So, the fastest way is by making subdomain with its own template.
        Rico
        Genius is one percent inspiration and ninety-nine percent perspiration. Thomas A. Edison
        MODx is great, but knowing how to use it well makes it perfect!

        www.virtudraft.com

        Security, security, security! | Indonesian MODx Forum | MODx Revo's cheatsheets | MODx Evo's cheatsheets

        Author of Easy 2 Gallery 1.4.x, PHPTidy, spieFeed, FileDownload R, Upload To Users CMP, Inherit Template TV, LexRating, ExerPlan, Lingua, virtuNewsletter, Grid Class Key, SmartTag, prevNext

        Maintainter/contributor of Babel

        Because it's hard to follow all topics on the forum, PING ME ON TWITTER @_goldsky if you need my help.
        • 1343 ☆ A M B ☆
        • 2,213 Posts
        Hello,

        I am going to be using domain.com/mobile as subdomains aren’t really a happening thing with Evolution and the site in question is based off Evolution (well 0.9.6.3). I am using @DOCUMENT ## for several of the pages so I don’t really want to spit the mobile site into a new location.

        The main problem is how can I automatically mobile devices to the mobile site and still allow them to return to the main site (clicking a link). Similar to with the mobile gmail interface.

        Thanks,
        AMDbuilder
          Patrick | Server Wrangler
          About Me: Website | Tweets |  MODX Hosting
          • 1343 ☆ A M B ☆
          • 2,213 Posts
          Bump, Anyone?

          I’m surprised nobody has already done this with the current amount of mobile devices getting online these days.

          AMDbuilder
            Patrick | Server Wrangler
            About Me: Website | Tweets |  MODX Hosting
            • 5340
            • 1,624 Posts
            I would create a snippet that will detect if the device is mobile device. The snippet has to sit at the top of your template
            Usually you do that by detecting the browser version. If the browser is mobile I would redirect to /mobile

            By default a mobile device will be shown the mobile version.

            In order to show the normal website when a link is clicked I would create a page for that link. That page will set a session variable ($_SESSION[mobileWebsite] = true) and redirect to the full version.

            I hope you got the idea
              • 16545
              • 358 Posts
                • 1343 ☆ A M B ☆
                • 2,213 Posts
                Quote from: xpix at Apr 16, 2009, 01:00 PM

                I would create a snippet that will detect if the device is mobile device. The snippet has to sit at the top of your template
                Usually you do that by detecting the browser version. If the browser is mobile I would redirect to /mobile

                By default a mobile device will be shown the mobile version.

                In order to show the normal website when a link is clicked I would create a page for that link. That page will set a session variable ($_SESSION[mobileWebsite] = true) and redirect to the full version.

                I hope you got the idea

                I get the idea, but I don’t know enough php to even know where to start on creating that form of functionality... Can you give any pointers on how I would accomplish this?

                Thanks,
                AMDbuilder
                  Patrick | Server Wrangler
                  About Me: Website | Tweets |  MODX Hosting
                  • 22851
                  • 805 Posts
                  Here’s a recipe which will allow you to use the same address for both mobile and normal sites. If the request looks like it is coming from a mobile device then the mobile template is used, else the normal template is used. I have something similar (but not exactly the same) implemented. The following is untested, but should work.

                  To implement this, first you need two chunks. NormalTpl contains your normal template, and MobileTpl contains your mobile template. You should then create a real template for your page that looks like this:
                  {{NormalTpl}}#####{{MobileTpl}}
                  


                  Next you need some php code that will analyse the HTTP headers on each page request and decide whether it’s a mobile device that has requested the page or not. You could use the detect mobile browsers script for example. That code should be executed every time the page is requested, so it needs to be called on the OnWebPagePrerender event.

                  So, the next step is to create a new plugin. Lets call it MobileSnifferTemplateChooser. From the system events tab, select the OnWebPagePrerender event. Within the General tab you need to do three things.
                  1. Include your favourite php mobile detection script. Save the result in a variable, called, for example, $isMobileDevice.
                  2. Include some code like the following, which will analyse your document content, and pick out the two templates.
                  list($normalTpl,$mobileTpl) = explode('#####', $modx->documentOutput);
                  

                  3. Choose the correct template
                  if ( $isMobileDevice )
                  {
                    $modx->documentOutput = $mobileTpl;
                  }
                  else
                  {
                    $modx->documentOutput = $normalTpl;
                  }
                  


                  That should be it. I’d love to hear if you tried it and if it works for you.
                    YAMS: Yet Another Multilingual Solution for MODx
                    YAMS Forums | Latest: YAMS 1.1.9 | YAMS Documentation
                    Please consider donating if you appreciate the time and effort spent developing and supporting YAMS.
                    • 4041
                    • 788 Posts
                    Completely untested, taken from the code I found here:
                    http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers

                    Create a snippet with this code, and put it in the very top of your template.

                    <?php
                    /*     Mobile browser redirect
                           original code: http://www.brainhandles.com/techno-thoughts/detecting-mobile-browsers
                           [!Mobile_redirect? &mID=`3`!]
                    */
                    // set the document ID of the mobile page
                    $redirect_to_mID = isset($mID) ? $mID : "3";
                    
                    if(isset($_SERVER["HTTP_X_WAP_PROFILE"]) || preg_match("/wap\.|\.wap/i",$_SERVER["HTTP_ACCEPT"])) {
                            header("Location: [~".$redirect_to_mID."~]");
                    }
                    
                    if(isset($_SERVER["HTTP_USER_AGENT"])){
                            if(preg_match("/Creative\ AutoUpdate/i",$_SERVER["HTTP_USER_AGENT"])) { return false; }
                            $uamatches = array("midp", "j2me", "avantg", "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: [~".$redirect_to_mID."~]");
                            }
                    }
                    
                    ?>


                    If it doesn’t work, maybe at least it will give a start point smiley

                    edit: typo in the last header() section fixed
                      xforum
                      http://frsbuilders.net (under construction) forum for evolution
                      • 33988
                      • 110 Posts
                      Thanks Breezer, I work with AMDBuilder and I implemented your code successfully. There is only one typo in the last header statement. The only problem we have now is that we want to also allow the user the option of switching back to the Full site, but this code forces the user to the mobile site. I was thinking something with a cookie or involving the referrer, but I’m not sure where to start with either.
                        Sal Sodano
                        President & Co-Founder of SkyToaster
                        My Website Salscode.