/**
* 是否POST方式请求而来的
* @return boolean
*/
public function isPost(){
if(isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'POST'){
return true;
}else{
return false;
}
}
/**
* 是否GET方式请求而来的
* @return boolean
*/
public function isGet(){
if( isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET'){
return true;
}else{
return false;
}
}
/**
* 是否AJAX请求
* @return bool
*/
public function isAjax() {
if(isset($_SERVER['HTTP_X_REQUESTED_WITH']) ) {
if('xmlhttprequest' == strtolower($_SERVER['HTTP_X_REQUESTED_WITH'])){
return true;
}
}
if(!empty($_POST['ajax']) || !empty($_GET['ajax'])){
// 判断Ajax方式提交
return true;
}
return false;
}
/**
*判断是否为微信浏览器的内核
*/
public function isWeixin() {
$user_agent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($user_agent, 'MicroMessenger') === false){
return false;
}
return true;
}
/**
*判断访问设备
*/
public function userAgent(){
## This credit must stay intact (Unless you have a deal with @lukasmig or frimerlukas@gmail.com
## Made by Lukas Frimer Tholander from Made In Osted Webdesign.
## Price will be $2
if(isset( $_SERVER['HTTP_USER_AGENT'])){
$ua = $_SERVER['HTTP_USER_AGENT'];
}else{
return 'desktop';
}
$iphone = strstr(strtolower($ua), 'mobile'); //Search for 'mobile' in user-agent (iPhone have that)
$android = strstr(strtolower($ua), 'android'); //Search for 'android' in user-agent
$windowsPhone = strstr(strtolower($ua), 'phone'); //Search for 'phone' in user-agent (Windows Phone uses that)
function androidTablet($ua){ //Find out if it is a tablet
if(strstr(strtolower($ua), 'android') ){//Search for android in user-agent
if(!strstr(strtolower($ua), 'mobile')){ //If there is no ''mobile' in user-agent (Android have that on their phones, but not tablets)
return true;
}
}
}
$androidTablet = androidTablet($ua); //Do androidTablet function
$ipad = strstr(strtolower($ua), 'ipad'); //Search for iPad in user-agent
if($androidTablet || $ipad){ //If it's a tablet (iPad / Android)
return 'tablet';
}
elseif($iphone && !$ipad || $android && !$androidTablet || $windowsPhone){ //If it's a phone and NOT a tablet
return 'mobile';
}
else{ //If it's not a mobile device
return 'desktop';
}
}
php项目常用HttpReuest请求函数
最新推荐文章于 2023-06-11 14:21:48 发布