From 4a974f52a9ede0877a90b706c56568b730ea8e0f Mon Sep 17 00:00:00 2001 From: thinkphp Date: Mon, 30 May 2016 22:49:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9BRequest=E7=B1=BB=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0agent=E5=92=8CisMobile=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/Request.php | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/library/think/Request.php b/library/think/Request.php index f483e6c3..e056c551 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -711,6 +711,36 @@ class Request return $ip[$type]; } + /** + * 获取用户agent信息 + * @access public + * @return string + */ + public function agent() + { + return $this->server('HTTP_USER_AGENT'); + } + + /** + * 检测是否使用手机访问 + * @access public + * @return bool + */ + public function isMobile() + { + if (isset($_SERVER['HTTP_VIA']) && stristr($_SERVER['HTTP_VIA'], "wap")) { + return true; + } elseif (strpos(strtoupper($_SERVER['HTTP_ACCEPT']), "VND.WAP.WML")) { + return true; + } elseif (isset($_SERVER['HTTP_X_WAP_PROFILE']) || isset($_SERVER['HTTP_PROFILE'])) { + return true; + } elseif (preg_match('/(blackberry|configuration\/cldc|hp |hp-|htc |htc_|htc-|iemobile|kindle|midp|mmp|motorola|mobile|nokia|opera mini|opera |Googlebot-Mobile|YahooSeeker\/M1A1-R2D2|android|iphone|ipod|mobi|palm|palmos|pocket|portalmmm|ppc;|smartphone|sonyericsson|sqh|spv|symbian|treo|up.browser|up.link|vodafone|windows ce|xda |xda_)/i', $_SERVER['HTTP_USER_AGENT'])) { + return true; + } else { + return false; + } + } + /** * 当前URL地址中的scheme参数 * @access public