Display short user agent (ie. ad links)

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

    Display short user agent (ie. ad links)

    This snippet is displaying short info of user agent like iPhone, Android, HTC, Nokia...
    I didn't intend to scrap all possible ua, just most commonly used.
    Any feedback is welcome.

    PHP Code:
    function shortua() {
        
    /* SNIPPET BY ARNAGE http://wapforum.rs * DOWNLOAD AT http://coding-talk.com */
    $userbrowser = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '';
    $userbrowser = isset($_SERVER['HTTP_X_OPERAMINI_PHONE_UA']) ? $_SERVER['HTTP_X_OPERAMINI_PHONE_UA'] : $userbrowser;
    $userbrowser = isset($_SERVER['HTTP_X_ORIGINAL_USER_AGENT']) ? $_SERVER['HTTP_X_ORIGINAL_USER_AGENT'] : $userbrowser;
    $userbrowser = isset($_SERVER['HTTP_X_DEVICE_USER_AGENT']) ? $_SERVER['HTTP_X_DEVICE_USER_AGENT'] : $userbrowser;
    $userbrowser = isset($_SERVER['HTTP_X_MOBILE_UA']) ? $_SERVER['HTTP_X_MOBILE_UA'] : $userbrowser;
    $userbrowser = isset($_SERVER['HTTP_X_BOLT_PHONE_UA']) ? $_SERVER['HTTP_X_BOLT_PHONE_UA'] : $userbrowser;
    $useragent = !empty($userbrowser) ? htmlentities($userbrowserENT_QUOTES'UTF-8') : 'Browser';
    if (
    strpos($useragent'/') !== false) {
        
    $agent explode('/'$useragent);
        if (
    stripos($useragent'Mini') !== false) {
            
    $short $agent[0].'Mini';
        }
        elseif (
    stripos($useragent'Nokia') !== false) {
            if (
    strcmp($agent[0], 'Mozilla') == 0)
                
    $short 'Nokia';
            else
                
    $short $agent[0];
        }
        elseif (
    stripos($useragent'iPhone') !== false) {
            
    $short 'iPhone';
        }
        elseif (
    stripos($useragent'MSIE') !== false) {
            if (
    stripos($useragent'HTC') !== false)
                
    $short 'HTC';
            elseif (
    stripos($useragent'IEMobile') !== false)
                
    $short 'WindowsMobile';
            else
                
    $short 'PC';
        }
        elseif (
    stripos($useragent'Android') !== false) {
            if (
    stripos($useragent'HTC') !== false)
                
    $short 'HTC Android';
            else
                
    $short 'Android';
        }
        elseif (
    stripos($useragent'BlackBerry') !== false) {
            
    $short 'BlackBerry';
        }
        elseif (
    stripos($useragent'lg-') !== false) {
            
    $short 'LG';
        }
        elseif (
    stripos($useragent'sie-') !== false) {
            
    $short 'Siemens';
        }
        elseif (
    stripos($useragent'Firefox') !== false) {
            
    $short 'PC';
        }
        elseif (
    stripos($useragent'Chrome') !== false) {
            
    $short 'PC';
        }
        else {
            
    $short $agent[0];
        }
    } else {
        
    $short mb_strlen($useragent'UTF-8') > 10 mb_substr($useragent010'UTF-8') : $useragent;
    }
    return 
    $short;

    Usage Example:
    PHP Code:
    echo '<a href="http://somead.tld/?ref=00001">Free '.shortua().' Downloads!</a>'
    Last edited by arnage; 30.11.11, 18:35. Reason: just >= to >
    <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

    #2
    Bro,I guess & I'm sure,you're the most talented php programmer on earth! I'm not flattering :D
    I need some facebook likes, can you please help me
    http://facebook.com/softwarefreakin
    I noticed social media is really powerful
    Well DONE is better than well SAID

    Comment


      #3
      Thanx Bro Its a Gr8

      Comment


        #4
        just awesome. really outstanding. thnx a lot

        http://WapTops.com- Get Real High Traffic
        http://WapFun.info-Fun 4 Wap

        Comment


          #5
          Thanks guys, i'm glad you like it.
          <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

          Comment

          Working...
          X