当我们采用php作为服务数据端口,为移动端,pc端提供数据接口的时候,可能会要求记录接口访问的来源是来之哪里.
function order_source() {
$useragent = strtolower($_SERVER["HTTP_USER_AGENT"]);
// iphone
$is_iphone = strripos($useragent,'iphone'); if($is_iphone){ return 'iphone'; }
// android
$is_android = strripos($useragent,'android');
if($is_android){ return 'android'; }
// 微信
$is_weixin = strripos($useragent,'micromessenger');
if($is_weixin){ return 'weixin'; }
// ipad
$is_ipad = strripos($useragent,'ipad');
if($is_ipad){ return 'ipad'; }
// ipod
$is_ipod = strripos($useragent,'ipod');
if($is_ipod){ return 'ipod'; }
// pc电脑
$is_pc = strripos($useragent,'windows nt');
if($is_pc){ return 'pc'; }
return 'other';
}
根据自己的需求 ,来做一些特殊处理比如区分浏览器,这里就不做介绍了.
发表评论