We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
  • Quote from: BobRay at Jan 16, 2014, 03:08 AM
    I think this would be it (though $mobile is never used for anything or returned):

    <!--?php
    
    // GET THE USER_AGENT
    $ua = (isset($_SERVER) && array_key_exists('HTTP_USER_AGENT', $_SERVER))
        ? $_SERVER['HTTP_USER_AGENT']
        : false;
    
    // TRUE IF MOBILE DEVICE
    $ismobile = (isset($_SERVER['AMF_ISMOBILE']))
        ? $_SERVER['AMF_ISMOBILE']
        : false;
    
    if (stristr($ua, 'windows') != '') $os = 'win';
    if (stristr($ua, 'mac') != '') $os = 'mac';
    if (stristr($ua, 'linux') != '') $os = 'linux';
    if (stristr($ua, 'android') != '') $os = 'android';
    if (stristr($ua, 'iphone') != '') $os = 'iphone';
    if (stristr($ua, 'ipad') != '') $os = 'ipad';
    
    $mobile = ($ismobile) ? ' mobile' : '';
    
    if (strpos($ua, 'firefox') !== false) {
        $ver = explode('/',$ua);
        $ver = explode('.',$ver[count($ver)-1]);
        $o = 'firefox ff-'.$ver[0].' ff-'.$os;
    
    } elseif (stripos($ua, 'opr') !== false) {
        $ver = explode('/',$ua);
        $ver = explode('.',$ver[count($ver)-1]);
        $o = 'opera opera-'.$ver[0].' opera-'.$os;
    } elseif (stripos($ua, 'safari') !== false && stripos($ua, 'chrome') === false) {
        $o = 'safari safari-'.$os;
    } elseif (stripos($ua, 'chrome') !== false) {
        $ver = explode('Chrome/',$ua);
        $ver = explode('.',$ver[1]);
        $o = 'chrome chrome-'.$ver[0].' chrome-'.$os;
    } elseif (stripos($ua, 'msie') !== false) {
        $ver = explode('MSIE ', $ua);
        $ver = explode('.', $ver[1]);
        $o = 'iexplore ie-'.$ver[0];
    } else {
        $o = 'browserunknown';
    }
    
    return $o;
    -->

    Hi again Bob,
    maybe is strange but this code is not work smiley
    i get this error:
    Parse error: syntax error, unexpected T_VARIABLE in /home/user/public_html/core/cache/includes/elements/modsnippet/91.include.cache.php on line 9
      palma non sine pulvere
      • 3749
      • 24,544 Posts
      The code you posted is valid except for the HTML comment tags.

      The beginning should be

      <?php


      and this line at the end should be removed:

      -->
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
      • Quote from: BobRay at Jan 22, 2014, 08:11 PM
        The code you posted is valid except for the HTML comment tags.

        The beginning should be

        <!--?php


        and this line at the end should be removed:

        ---->

        actually my code is:
        <?php
         
        // GET THE USER_AGENT
        $ua = (isset($_SERVER) && array_key_exists('HTTP_USER_AGENT', $_SERVER))
            ? $_SERVER['HTTP_USER_AGENT']
            : false;
         
        // TRUE IF MOBILE DEVICE
        $ismobile = (isset($_SERVER['AMF_ISMOBILE']))
            ? $_SERVER['AMF_ISMOBILE']
            : false;
         
        if (stristr($ua, 'windows') != '') $os = 'win';
        if (stristr($ua, 'mac') != '') $os = 'mac';
        if (stristr($ua, 'linux') != '') $os = 'linux';
        if (stristr($ua, 'android') != '') $os = 'android';
        if (stristr($ua, 'iphone') != '') $os = 'iphone';
        if (stristr($ua, 'ipad') != '') $os = 'ipad';
         
        $mobile = ($ismobile) ? ' mobile' : '';
         
        if (strpos($ua, 'firefox') !== false) {
            $ver = explode('/',$ua);
            $ver = explode('.',$ver[count($ver)-1]);
            $o = 'firefox ff-'.$ver[0].' ff-'.$os;
         
        } elseif (stripos($ua, 'opr') !== false) {
            $ver = explode('/',$ua);
            $ver = explode('.',$ver[count($ver)-1]);
            $o = 'opera opera-'.$ver[0].' opera-'.$os;
        } elseif (stripos($ua, 'safari') !== false && stripos($ua, 'chrome') === false) {
            $o = 'safari safari-'.$os;
        } elseif (stripos($ua, 'chrome') !== false) {
            $ver = explode('Chrome/',$ua);
            $ver = explode('.',$ver[1]);
            $o = 'chrome chrome-'.$ver[0].' chrome-'.$os;
        } elseif (stripos($ua, 'msie') !== false) {
            $ver = explode('MSIE ', $ua);
            $ver = explode('.', $ver[1]);
            $o = 'iexplore ie-'.$ver[0];
        } else {
            $o = 'browserunknown';
        }
         
        return $o;


        maybe is fun or It is unbelievable but is not work i get same error:
        Parse error: syntax error, unexpected T_VARIABLE in /home/user/public_html/core/cache/includes/elements/modsnippet/91.include.cache.php on line 9
          palma non sine pulvere
        • Your code works fine for me. Well, it's returning browserunknown, but at least it's not causing any errors. I used strtolower($ua) and that took care of it not finding Firefox. [ed. note: sottwell last edited this post 10 years, 2 months ago.]
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
          • Quote from: sottwell at Jan 29, 2014, 08:29 PM
            Your code works fine for me. Well, it's returning browserunknown, but at least it's not causing any errors.
            i thing is not normal to return browserunknown smiley
            when i run outside this php script get something like that:
            <body class="nojs chrome chrome-32 chrome-mac mac">
              palma non sine pulvere
            • That's because my user-agent is Firefox, not firefox. I added a strtolower($ua) and it's fine now.

               Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:26.0) Gecko/20100101 Firefox/26.0
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
              • i thing is no matter is Firefox or firefox because in original script when i open with FF i get:
                <body class="nojs firefox ff-26 ff-mac mac">
                  palma non sine pulvere