PHP限制页面只能在微信自带浏览器访问的代码_php技巧

WBOY
Release: 2016-05-17 08:51:08
Original
1455 people have browsed it

为了防止自己辛辛苦苦做的webapp被人copy,我们都想限制程序只能在微信里面浏览,虽然下面实现了这个功能,单都是小菜,没什么技术含量,懂代码的伪造下就破了。下面是PHP限制页面只能在微信自带浏览器访问的代码。

复制代码 代码如下:

$useragent = $_SERVER['HTTP_USER_AGENT'];
if (strpos($useragent, 'MicroMessenger') === false) {
echo " 非微信浏览器禁止访问";
} else {
echo "微信浏览器允许访问";
}

上面这个代码还不完善,Windows phone的微信就不能用了,于是修改下:
复制代码 代码如下:

$useragent = addslashes($_SERVER['HTTP_USER_AGENT']);
if(strpos($useragent, 'MicroMessenger') === false && strpos($useragent, 'Windows Phone') === false ){
echo " 非微信浏览器禁止访问www.buyerinfo.biz";
}else{
echo "微信浏览器允许访问www.buyerinfo.biz";
}

大家可以通过获取 HTTP_USER_AGEN,判断。

但是你觉得上面的方法能阻止别人去偷窃你的界面,你就错了,只要伪造一下HTTP_USER_AGEN还是能正常访问。
在谷歌浏览器上面装个User-Agent Switcher,还是能随便访问。于是我还想到用JS来判断是不是手机访问,但是只要浏览器禁止JS运行,还是能正常访问。。不过或许这样能难到一些新手吧。
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!