功能需求:根据蜘蛛,移动设备,pc设备进行适配不同设备,来更好适应用户体验
封装代码如下:
function is_robot() { //判断360蜘蛛,百度蜘蛛,goole蜘蛛 return preg_match("/(bot|360Spider|Baiduspider)/i", $_SERVER['HTTP_USER_AGENT']); } function is_wap() { return preg_match("/(Android|ipad|iPhone|NOKIA|BlackBerry|iPod|symbian|mobile|wap|YisouSpider)/i", $_SERVER['HTTP_USER_AGENT']); } function is_touch() { $ck = get_cookie('mobile'); if($ck == 'pc') return 0; if($ck == 'touch' || $ck == 'screen') return 1; return preg_match("/(iPhone|iPad|iPod|Android)/i", $_SERVER['HTTP_USER_AGENT']) ? 1 : 0; }