WeChat is quite popular now, and more and more applications are being developed around WeChat. Some time ago, my company needed to write a WeChat application in PHP. In order to prevent the PHP application I worked hard to write from being stolen, Therefore, restrictions were made through PHP. This application can only be opened in the browser that comes with WeChat. I had no clue at first, but after much verification, I finally figured out this function. Now I will share the specific code with you.
1
2$useragent = addslashes($_SERVER['HTTP_USER_AGENT']);
3if(strpos($useragent, 'MicroMessenger') === false && strpos($useragent, 'Windows Phone') === false ){
4echo "Sorry! Non-WeChat browsers cannot access";
5}else{
6echo "Can access";
7}
8?>
Note: If the HTTP_USER_AGEN method is forged in the above method, you can access it normally. Game masters can also access it if they install a User-Agent Switcher on Google Chrome. Later I thought of using JS to determine whether the access is from a mobile phone, but this cannot completely solve the problem, because if the client browser disables JS, this method will be ineffective, so I think it is just like blocking the right click on the web page. It can stump some people who don’t understand, alas.