function isMobeil() { if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { alert('手機端') }else{ alert('PC端') } }
function isBrowser() { var userAgent = navigator.userAgent; //微信內置瀏覽器 if(userAgent.match(/MicroMessenger/i) == 'MicroMessenger') { return "Wx"; } //QQ內置瀏覽器 else if(userAgent.match(/QQ/i) == 'QQ') { return "QQ"; } //Chrome else if(userAgent.match(/Chrome/i) == 'Chrome') { return "Chrome"; } //Opera else if(userAgent.match(/Opera/i) == 'Opera') { return "Opera"; } //Firefox else if(userAgent.match(/Firefox/i) == 'Firefox') { return "Firefox"; } //Safari else if(userAgent.match(/Safari/i) == 'Safari') { return "Safari"; } //IE else if(!!window.ActiveXObject || "ActiveXObject" in window) { return "IE"; } else { return "未定義:"+userAgent; } }
//判斷用戶設備是手機仍是 pc,手機端返回 true ,pc 端返回 false public function isMobile(){ // 若是有HTTP_X_WAP_PROFILE則必定是移動設備 if (isset ($_SERVER['HTTP_X_WAP_PROFILE'])){ return TRUE; } // 若是via信息含有wap則必定是移動設備,部分服務商會屏蔽該信息 if (isset ($_SERVER['HTTP_VIA'])){ return stristr($_SERVER['HTTP_VIA'], "wap") ? TRUE : FALSE;// 找不到爲flase,不然爲TRUE } // 判斷手機發送的客戶端標誌,兼容性有待提升 if (isset ($_SERVER['HTTP_USER_AGENT'])) { $clientkeywords = array ( 'mobile', 'nokia', 'sony', 'ericsson', 'mot', 'samsung', 'htc', 'sgh', 'lg', 'sharp', 'sie-', 'philips', 'panasonic', 'alcatel', 'lenovo', 'iphone', 'ipod', 'blackberry', 'meizu', 'android', 'netfront', 'symbian', 'ucweb', 'windowsce', 'palm', 'operamini', 'operamobi', 'openwave', 'nexusone', 'cldc', 'midp', 'wap' ); // 從HTTP_USER_AGENT中查找手機瀏覽器的關鍵字 if (preg_match("/(" . implode('|', $clientkeywords) . ")/i", strtolower($_SERVER['HTTP_USER_AGENT']))){ return TRUE; } } if (isset ($_SERVER['HTTP_ACCEPT'])){ // 協議法,由於有可能不許確,放到最後判斷 // 若是隻支持wml而且不支持html那必定是移動設備 // 若是支持wml和html可是wml在html以前則是移動設備 if ((strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') !== FALSE) && (strpos($_SERVER['HTTP_ACCEPT'], 'text/html') === FALSE || (strpos($_SERVER['HTTP_ACCEPT'], 'vnd.wap.wml') < strpos($_SERVER['HTTP_ACCEPT'], 'text/html')))){ return TRUE; } } return FALSE; }
//獲取瀏覽器類型 public function getBrowser() { $agent = $_SERVER['HTTP_USER_AGENT']; if(strpos($agent, 'MicroMessenger') !== false){ echo "wx"; }else if(strpos($agent, 'QQ') !== false){ echo "qq"; } else{ echo "other"; } }
// 若是是https 鏈接返回true ,不然返回false public function isHttps() { if ( !empty($_SERVER['HTTPS']) && strtolower($_SERVER['HTTPS']) !== 'off') { return true; } elseif ( isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] === 'https' ) { return true; } elseif ( !empty($_SERVER['HTTP_FRONT_END_HTTPS']) && strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) !== 'off') { return true; } return false; }
/** * 獲取客戶端IP地址 * @param integer $type 返回類型 0 返回IP地址 1 返回IPV4地址數字 * @param boolean $adv 是否進行高級模式獲取(有可能被假裝) * @return mixed */ function get_client_ip($type = 0,$adv=false) { $type = $type ? 1 : 0; static $ip = NULL; if ($ip !== NULL) return $ip[$type]; if($adv){ if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) { $arr = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']); $pos = array_search('unknown',$arr); if(false !== $pos) unset($arr[$pos]); $ip = trim($arr[0]); }elseif (isset($_SERVER['HTTP_CLIENT_IP'])) { $ip = $_SERVER['HTTP_CLIENT_IP']; }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } }elseif (isset($_SERVER['REMOTE_ADDR'])) { $ip = $_SERVER['REMOTE_ADDR']; } // IP地址合法驗證 $long = sprintf("%u",ip2long($ip)); $ip = $long ? array($ip, $long) : array('0.0.0.0', 0); return $ip[$type]; }