微信浏览器的http_user_agent
在iphone下,返回
mozilla/5.0 (iphone; cpu iphone os 5_1 like mac os x) applewebkit/534.46 (khtml, like gecko) mobile/9b176 micromessenger/4.3.2)
在android下,返回
mozilla/5.0 (linux; u; android 2.3.6; zh-cn; gt-s5660 build/gingerbread) applewebkit/533.1 (khtml, like gecko) version/4.0 mobile safari/533.1 micromessenger/4.5.255)
不难发现微信浏览器为 micromessenger ,并且有版本号,也可以判断手机类型为iphone还是android
如果要做盗链
if(strpos($_server[http_user_agent],micromessenger)) echo welcome to wechat word;else echo http/1.1 401 unauthorized;public function is_weixin(){ if ( strpos($_server['http_user_agent'], 'micromessenger') !== false ) { return true;} return false;} if($this->is_weixin()){ }else{ echo 请使用微信访问本网址。;}
js判断
function is_weixin(){ var ua = navigator.useragent.tolowercase(); if(ua.match(/micromessenger/i)==micromessenger) { return true; } else { return false; }}
当在手机端判断到微信浏览器之后,可以使用微信的分享js脚本对其进行处理,大家可以参考微信的官方文档,这里提供一个案例,了解下大概流程和思路