Home >php教程 >php手册 >PHP限制网页只能在微信内置浏览器中查看并显示

PHP限制网页只能在微信内置浏览器中查看并显示

WBOY
WBOYOriginal
2016-06-13 09:37:431802browse

   微信现在算是火了,围绕微信开发的应用也越来越多了,前段时间,自己公司需要,用PHP写了一个微信应用,为了防止自己辛苦写成的PHP应用被盗用,于是通过PHP做了限制,只能在微信自带的浏览器中才能打开本应用,一开始无头绪,后经多查证,总算把这功能弄出来了,现在把具体的代码分享给大家。

  1

  2$useragent = addslashes($_SERVER['HTTP_USER_AGENT']);

  3if(strpos($useragent, 'MicroMessenger') === false && strpos($useragent, 'Windows Phone') === false ){

  4echo " Sorry!非微信浏览器不能访问";

  5}else{

  6echo "可以访问";

  7}

  8?>

  注:上述方法如果伪造了HTTP_USER_AGEN方法,就能正常访问了。玩机达人若在谷歌浏览器上装个User-Agent Switcher,同样也可访问。后来想到用JS来判断是不是手机访问,但这样同样不能彻底解决问题,因为客户端浏览器若禁止了JS,该方法又失效了,所以我想,这就像在网页上屏蔽右键一样,只能难倒一些不懂的人,唉。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn