Announcement

Collapse
No announcement yet.

Detect User Agent

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Detect User Agent

    Is there any handy dandy detect user agent script that can be added to the index.html page of a store? I need to redirect from the index.html page to the SFNT if a module device is being used. The site doesn't use the SFNT as it's homepage (and doesn't want to) but wants to use the Mobile Commerce it has had installed.

    Thanks,
    Leslie
    Leslie Kirk
    Miva Certified Developer
    Miva Merchant Specialist since 1997
    Previously of Webs Your Way
    (aka Leslie Nord leslienord)

    Email me: [email protected]
    www.lesliekirk.com

    Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

    #2
    Re: Detect User Agent

    Mobile agent detection is definitely a moving target. In any case, the variables containing the user agent are there; from a .htaccess perspective it would be RewriteCond %{HTTP_USER_AGENT}

    If the index page is php, or can be made php, the variable would be: $_SERVER['HTTP_USER_AGENT']

    Alternatively, there's an even easier way if the existing index page is index.html. Create a new index.php and use the php-mobile-detect google project code:

    http://code.google.com/p/php-mobile-detect/

    All you'd have to do is load the Mobile_Detect.php script to the httpdocs directory, leave your existing index.html as-is and make a new index.php page that looks like this (no blank lines at the top):

    PHP Code:
    <?php
    include 'Mobile_Detect.php';
    $detect = new Mobile_Detect();

    if ( 
    $detect->isMobile() ) {
        
    header('Location: http://www.domain.com/mm5/merchant.mvc');
    } else {
        
    readfile("index.html");
    }
    ?>
    Basically what it does is incoming requests, since index.php takes precedence over index.html, execute the php page, the mobile detection code triggers, if the browser is mobile it gets redirected, if not, the contents of the index.html file are output. Keep in mind the detection script updates pretty frequently so it would need to be kept up with.
    Last edited by ILoveHostasaurus; 06-06-13, 11:17 AM.
    David Hubbard
    CIO
    Miva
    [email protected]
    http://www.miva.com

    Comment


      #3
      Re: Detect User Agent

      Looks like the "easy" way isn't going to play nicely with the site. It seems to interfere with the usage of includes. The include directive is in the .htaccess file and when I tried using the index.php the includes didn't include them self in the index.html file like they need to.

      Leslie
      Leslie Kirk
      Miva Certified Developer
      Miva Merchant Specialist since 1997
      Previously of Webs Your Way
      (aka Leslie Nord leslienord)

      Email me: [email protected]
      www.lesliekirk.com

      Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

      Comment


        #4
        Re: Detect User Agent

        Here is a JavaScript version we use on static pages. It checks to the user-agent is JS against the main phone OSs on the market today and will redirect to the Miva Storefront if it matches. The android check is pretty blanket so it would included phones as well as tablets.

        Code:
        <script>
            var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
            if (mobile) { 
                document.location = "http://www.yourdomain.com/mm5/merchant.mvc?Screen=SFNT&Store_Code=XX";
            } 
        </script>
        Brennan Heyde
        VP Product
        Miva, Inc.
        [email protected]
        https://www.miva.com

        Comment


          #5
          Re: Detect User Agent

          Just my personal opinion but I have a tablet I use a lot (Samsung Galaxy 10.1 ICS) and prefer sites that let me select full version and then keep me on the full version after I've made that choice. I can't count the number of sites that I want to use some functionality of that requires the full version, has a link to display full version, and then one click later I'm back on mobile version. Drives me crazy. :-)
          David Hubbard
          CIO
          Miva
          [email protected]
          http://www.miva.com

          Comment


            #6
            Re: Detect User Agent

            Yea, that's why some of buy android tablets...they don't really have a problem with the web<g>.
            Bruce Golub
            Phosphor Media - "Your Success is our Business"

            Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
            phosphormedia.com

            Comment


              #7
              Re: Detect User Agent

              Originally posted by Brennan View Post
              Here is a JavaScript version we use on static pages. It checks to the user-agent is JS against the main phone OSs on the market today and will redirect to the Miva Storefront if it matches. The android check is pretty blanket so it would included phones as well as tablets.

              Code:
              <script>
                  var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));  
                  if (mobile) { 
                      document.location = "http://www.yourdomain.com/mm5/merchant.mvc?Screen=SFNT&Store_Code=XX";
                  } 
              </script>
              So instead of the PHP page thing, I can use this on the HTML pages?
              Leslie Kirk
              Miva Certified Developer
              Miva Merchant Specialist since 1997
              Previously of Webs Your Way
              (aka Leslie Nord leslienord)

              Email me: [email protected]
              www.lesliekirk.com

              Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

              Comment


                #8
                Re: Detect User Agent

                Originally posted by ILoveHostasaurus View Post
                Just my personal opinion but I have a tablet I use a lot (Samsung Galaxy 10.1 ICS) and prefer sites that let me select full version and then keep me on the full version after I've made that choice. I can't count the number of sites that I want to use some functionality of that requires the full version, has a link to display full version, and then one click later I'm back on mobile version. Drives me crazy. :-)
                I can see where this can be confusing and a potential problem. If I click the Desktop link for the site I'm using this on, I get taken to the SFNT screen instead of the index page. I can see where this would probably just loop me back to the SFNT.

                Any way around it?
                Leslie Kirk
                Miva Certified Developer
                Miva Merchant Specialist since 1997
                Previously of Webs Your Way
                (aka Leslie Nord leslienord)

                Email me: [email protected]
                www.lesliekirk.com

                Follow me: Twitter | Facebook | FourSquare | Pinterest | Flickr

                Comment


                  #9
                  Re: Detect User Agent

                  Did you find a solution to this?

                  I am having a similar issue. The site doesn't use the SFNT page but a static html page for it's home page. We have a mobile storefront. When I view the home page on an Android tablet, I am getting the SFNT page (it is blank). I have redirects setup in the .htaccess file to use the index.html page:
                  Code:
                  RewriteCond %{THE_REQUEST} ^.*/SFNT.html
                  RewriteRule ^(.*)SFNT.html$ /index.htm [R=301,L]
                  
                  RewriteCond %{QUERY_STRING} Screen=SFNT&Store_Code=ws [NC]
                  RewriteRule ^(.*)$ /index.htm? [R=301,L]
                  Any ideas how to resolve this? It is probably an issue on ipad's as well.

                  Comment

                  Working...
                  X