为了更好的用户体验,本主题默认支持wap和web两种访问样式,wap访问将不包含任何脚本、样式也是重新撰写,不支持更多页面,只支持首页、详情页, 评论框、登录等内容将陆续更新到wap内容里。如果想测试,您可以使用手机访问http://qianduanblog.com试试看,是不是效果和电脑 访问不一样?
下面贴出获得访问类型的函数(来源于互联网):
经测试,下面判断是错误的。
- /***************************************************
- ** 返回访问的类型(wap web)
- ** 2012年12月2日22:21:20
- ***************************************************/
- function yundanran_get_access_type()
- {
- $is_wap=false;
- // 如果有HTTP_X_WAP_PROFILE则一定是移动设备
- if (isset($_SERVER[‘HTTP_X_WAP_PROFILE‘]))
- {
- $is_wap=true;
- }
- else
- {
- // 如果via信息含有wap则一定是移动设备,部分服务商会屏蔽该信息
- if(isset($_SERVER[‘HTTP_VIA‘]))
- {
- // 找不到为flase,否则为true
- $is_wap=stristr($_SERVER[‘HTTP_VIA‘],"wap") ? true : false;
- }
- else
- {
- // 协议法,因为有可能不准确,放到最后判断
- 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‘)))
- )
- {
- $is_wap=true;
- }
- }
- }
- }
- return $is_wap?‘wap‘:‘web‘;
- }
- 正确的判断方法,将会近期写出:
╮(╯▽╰)╭,笨方法,用UA判断,源自大前端:
-
- /***************************************************
- ** 返回访问的类型(wap web)
- ** 2012年12月2日22:21:20
- ** 2012年12月3日22:30:00
- ***************************************************/
- function yundanran_get_access_type()
- {
- $is_wap=false;
- $user_agent = $_SERVER[‘HTTP_USER_AGENT‘];
- $mobile_agents = Array
- (
- "240x320","acer","acoon","acs-","abacho","ahong","airness",
- "alcatel","amoi","android","anywhereyougo.com","applewebkit/525",
- "applewebkit/532","asus","audio","au-mic","avantogo",
- "becker","benq","bilbo","bird","blackberry","blazer","bleu",
- "cdm-","compal","coolpad","danger","dbtel","dopod","elaine",
- "eric","etouch","fly ","fly_","fly-","go.web","goodaccess",
- "gradiente","grundig","haier","hedy","hitachi","htc",
- "huawei","hutchison","inno","ipad","ipaq","ipod","jbrowser",
- "kddi","kgt","kwc","lenovo","lg ","lg2","lg3","lg4","lg5",
- "lg7","lg8","lg9","lg-","lge-","lge9","longcos","maemo",
- "mercator","meridian","micromax","midp","mini","mitsu",
- "mmm","mmp","mobi","mot-","moto","nec-","netfront","newgen",
- "nexian","nf-browser","nintendo","nitro","nokia","nook",
- "novarra","obigo","palm","panasonic","pantech","philips",
- "phone","pg-","playstation","pocket","pt-","qc-","qtek",
- "rover","sagem","sama","samu","sanyo","samsung","sch-",
- "scooter","sec-","sendo","sgh-","sharp","siemens","sie-",
- "softbank","sony","spice","sprint","spv","symbian","tablet",
- "talkabout","tcl-","teleca","telit","tianyu","tim-","toshiba",
- "tsm","up.browser","utec","utstar","verykool","virgin","vk-",
- "voda","voxtel","vx","wap","wellco","wig browser","wii",
- "windows ce","wireless","xda","xde","zte"
- );
- $is_wap = false;
- foreach ($mobile_agents as $device)
- {
- if (stristr($user_agent, $device))
- {
- $is_wap = true;
- break;
- }
- }
- return $is_wap?‘wap‘:‘web‘;
- }
- 转载自 http://qianduanblog.com/post/php-get-access-source.html
时间: 2024-11-05 12:25:50