The best way to discover mobile users in Magento

What is the best way to determine if a user is a mobile user at the code level?

An administrator can set regex-based rules to detect and switch themes based on a user agent, but it seems that this function is "protected" inside the api and is not available as a set of methods that every developer can use.

I understand that developers and designers should set their functionality in folders so that they are accessible / inaccessible, but this is a rather difficult requirement for extension providers, because regex rules can be somewhat vaguely defined, and the administrator should not indicate whether the topic designed for mobile users

So, maybe someone has a good method to sniff it out of the kernel already (without reusing the material so that it is publicly available, and not protected, which is already available core/design_package)?

+5
source share
2 answers

You can try the following way:

  • Create a new store for your site with your own type of store, which is configured to use the desired package of mobile themes.
  • index.php - - ( , php)

Mage::run($mageRunCode, $mageRunType);

  • if (is_mobile()) {   Mage:: ( 'mobile_store_code'); } else {   Mage:: run ($ mageRunCode, $mageRunType); }

.

UPD: , decet:

function is_mobile() {
  $user_agent=strtolower(getenv('HTTP_USER_AGENT'));
  $accept=strtolower(getenv('HTTP_ACCEPT'));

  if ((strpos($accept,'text/vnd.wap.wml')!==false) ||
      (strpos($accept,'application/vnd.wap.xhtml+xml')!==false)) {
    return 1; 
  }

  if (isset($_SERVER['HTTP_X_WAP_PROFILE']) ||
      isset($_SERVER['HTTP_PROFILE'])) {
    return 2;
  } 
  return 0;
}

, http://www.manhunter.ru/webmaster/272_opredelenie_mobilnih_brauzerov_na_php.html

function isMobile()  
{  
    $regex_match = "/(nokia|iphone|android|motorola|^mot\-|softbank|foma|docomo|kddi|up\.browser|up\.link|"  
                 . "htc|dopod|blazer|netfront|helio|hosin|huawei|novarra|CoolPad|webos|techfaith|palmsource|"  
                 . "blackberry|alcatel|amoi|ktouch|nexian|samsung|^sam\-|s[cg]h|^lge|ericsson|philips|sagem|wellcom|bunjalloo|maui|"  
                 . "symbian|smartphone|mmp|midp|wap|phone|windows ce|iemobile|^spice|^bird|^zte\-|longcos|pantech|gionee|^sie\-|portalmmm|"  
                 . "jig\s browser|hiptop|^ucweb|^benq|haier|^lct|opera\s*mobi|opera\*mini|320x320|240x320|176x220"  
                 . ")/i";  

    if (preg_match($regex_match, strtolower($_SERVER['HTTP_USER_AGENT']))) {  
        return TRUE;  
    }  

    if ((strpos(strtolower($_SERVER['HTTP_ACCEPT']),'application/vnd.wap.xhtml+xml') > 0) or ((isset($_SERVER['HTTP_X_WAP_PROFILE']) or isset($_SERVER['HTTP_PROFILE'])))) {  
        return TRUE;  
    }      

    $mobile_ua = strtolower(substr($_SERVER['HTTP_USER_AGENT'], 0, 4));  
    $mobile_agents = array(  
        'w3c ','acs-','alav','alca','amoi','audi','avan','benq','bird','blac',  
        'blaz','brew','cell','cldc','cmd-','dang','doco','eric','hipt','inno',  
        'ipaq','java','jigs','kddi','keji','leno','lg-c','lg-d','lg-g','lge-',  
        'maui','maxo','midp','mits','mmef','mobi','mot-','moto','mwbp','nec-',  
        'newt','noki','oper','palm','pana','pant','phil','play','port','prox',  
        'qwap','sage','sams','sany','sch-','sec-','send','seri','sgh-','shar',  
        'sie-','siem','smal','smar','sony','sph-','symb','t-mo','teli','tim-',  
        'tosh','tsm-','upg1','upsi','vk-v','voda','wap-','wapa','wapi','wapp',  
        'wapr','webc','winw','winw','xda ','xda-');  

    if (in_array($mobile_ua,$mobile_agents)) {  
        return TRUE;  
    }  

    if (isset($_SERVER['ALL_HTTP']) && strpos(strtolower($_SERVER['ALL_HTTP']),'OperaMini') > 0) {  
        return TRUE;  
    }  

    return FALSE;  
}  

, http://snippy.ru/snippet/1864-Prostoy_sposob_opredelit_zahod_na_stranicu_cherez_mobilnyy_brauzer/

Google;)

+5

? , .

$isMobile = Zend_Http_UserAgent_Mobile::match(
    Mage::helper('core/http')->getHttpUserAgent(),
    $_SERVER
);

, , wurfl , .

+14

All Articles