本文整理汇总了PHP中waRequest::mobile方法的典型用法代码示例。如果您正苦于以下问题:PHP waRequest::mobile方法的具体用法?PHP waRequest::mobile怎么用?PHP waRequest::mobile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类waRequest
的用法示例。
在下文中一共展示了waRequest::mobile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: isMobile
/**
* Determines the use of a mobile device.
*
* @param bool $check Flag requiring to check and update the value of field nomobile in user's PHP session.
* If set to true, the following actions are performed:
* - If the GET request contains variable named 'nomobile' with a value equivalent to true, then field 'nomobile'
* in user's PHP session is set to true. If the value of this variable is equivalent to false, then field
* 'nomobile' is removed from user's session.
* - If the GET request contains no variable named 'nomobile' and does contain a variable named 'mobile' with
* a value equivalent to true, then field 'nomobile' is removed from user's session.
* - If, upon execution of the above actions, the value of field 'nomobile' in user's PHP session is equal to
* true, then method returns false. Otherwise the method continues its operation so as if the value of this
* flag were equal to false.
* If the flag's value is set to false, the use of a mobile device is determined by the contents of
* HTTP_USER_AGENT header.
*
* @return string|bool If mobile device is detected, one of these identifiers is returned: 'android', 'blackberry',
* 'iphone', 'opera', 'palm', 'windows', 'generic'; otherwise method return false.
*/
public static function isMobile($check = true)
{
if ($check) {
if (self::get('nomobile') !== null) {
if (self::get('nomobile')) {
waSystem::getInstance()->getStorage()->write('nomobile', true);
} else {
waSystem::getInstance()->getStorage()->remove('nomobile');
}
} elseif (self::get('mobile')) {
waSystem::getInstance()->getStorage()->remove('nomobile');
}
if (waSystem::getInstance()->getStorage()->read('nomobile')) {
return false;
}
}
if (self::$mobile !== null) {
return self::$mobile;
}
$user_agent = self::server('HTTP_USER_AGENT');
$desktop_platforms = array('ipad' => 'ipad', 'galaxy-tab' => 'android.*?GT\\-P');
foreach ($desktop_platforms as $pattern) {
if (preg_match('/' . $pattern . '/i', $user_agent)) {
self::$mobile = false;
return false;
}
}
$mobile_platforms = array("google-mobile" => "googlebot\\-mobile", "android" => "android", "blackberry" => "(blackberry|rim tablet os)", "iphone" => "(iphone|ipod)", "opera" => "opera (mini|mobi|mobile)", "palm" => "(palmos|avantgo|blazer|elaine|hiptop|palm|plucker|xiino)", "windows" => "windows\\sce;\\s(iemobile|ppc|smartphone)", "generic" => "(kindle|mobile|mmp|midp|o2|pda|pocket|psp|symbian|smartphone|treo|up.browser|up.link|vodafone|wap)");
foreach ($mobile_platforms as $id => $pattern) {
if (preg_match('/' . $pattern . '/i', $user_agent)) {
self::$mobile = $id;
return $id;
}
}
self::$mobile = false;
return false;
}