在PHP开发中经常需要获取到用户输入的一些信息,比方说需要从用户在表单中提交的数据中提取出手机号,下面这个PHP类就可以获取到手机号和手机User-Agent(UA)信息。
<?php
class mobile{
function getPhoneNumber(){
if (isset($_SERVER['HTTP_X_NETWORK_INFO'])){
$str1 = $_SERVER['HTTP_X_NETWORK_INFO'];
$getstr1 = preg_replace('/(.*,)(11[d])(,.*)/i','',$str1);
return $getstr1;
}elseif (isset($_SERVER['HTTP_X_UP_CALLING_LINE_ID'])){
$getstr2 = $_SERVER['HTTP_X_UP_CALLING_LINE_ID'];
return $getstr2;
}elseif (isset($_SERVER['HTTP_X_UP_SUBNO'])){
$str3 = $_SERVER['HTTP_X_UP_SUBNO'];
$getstr3 = preg_replace('/(.*)(11[d])(.*)/i','',$str3);
return $getstr3;
}elseif (isset($_SERVER['DEVICEID'])){
return $_SERVER['DEVICEID'];
}else{
return false;
}
}
function getHttpHeader(){
$str = '';
foreach ($_SERVER as $key=>$val){
$gstr = str_replace("&","&",$val);
$str.= "$key -> ".$gstr." ";
}
return $str;
}
function getUA(){
if (isset($_SERVER['HTTP_USER_AGENT'])){
return $_SERVER['HTTP_USER_AGENT'];
}else{
return false;
}
}
function getPhoneType(){
$ua = $this->getUA();
if($ua!=false){
$str = explode(' ',$ua);
return $str[0];
}else{
return false;
}
}
function isOpera(){
$uainfo = $this->getUA();
if (preg_match('/.*Opera.*/i',$uainfo)){
return true;
}else{
return false;
}
}
function isM3gate(){
$uainfo = $this->getUA();
if (preg_match('/M3Gate/i',$uainfo)){
return true;
}else{
return false;
}
}
function getHttpAccept(){
if (isset($_SERVER['HTTP_ACCEPT'])){
return $_SERVER['HTTP_ACCEPT'];
}else{
return false;
}
}
function getIP(){
$ip=getenv('REMOTE_ADDR');
$ip_ = getenv('HTTP_X_FORWARDED_FOR');
if (($ip_ != "") && ($ip_ != "unknown")){
$ip=$ip_;
}
return $ip;
}
}
本站原创内容,如需转载请注明来源:https://www.liutonghui.com/69.html
评论列表(0条)
暂时没有评论!