How does PHP restrict pages to be accessed only in WeChat's built-in browser?

WBOY
Release: 2016-07-25 09:12:00
Original
1459 people have browsed it

Restrict the program to only be viewed in WeChat. The following is the PHP code that restricts the page to only be accessed in WeChat's own browser.

In order to prevent the webapp that I have worked so hard to make from being copied, I want to limit the program to browsing in WeChat. Although this function is implemented below, it is just a side dish with no technical content. It will be broken by someone who knows the code. The following is the PHP code that restricts the page to be accessed only in WeChat’s own browser.

Example:

  1. $useragent = $_SERVER['HTTP_USER_AGENT'];
  2. if (strpos($useragent, 'MicroMessenger') === false) {
  3. echo "Access is prohibited by non-WeChat browsers";
  4. } else {
  5. echo "Access is allowed by WeChat browsers";
  6. }
Copy the code

The above code is not perfect, and WeChat on Windows phone cannot be used. , so modify it:

  1. $useragent = addslashes($_SERVER['HTTP_USER_AGENT']);
  2. if(strpos($useragent, 'MicroMessenger') === false && strpos($useragent, 'Windows Phone') === false ){
  3. echo "Non-WeChat browsers are prohibited from accessing bbs.it-home.org";
  4. }else{
  5. echo "WeChat browsers are allowed to access bbs. it-home.org";
  6. }
Copy code

You can judge by getting HTTP_USER_AGEN.

However, the above code can still be accessed normally as long as HTTP_USER_AGEN is forged. Install a User-Agent Switcher on Google Chrome and you can still access it at will. So I also thought of using JS to determine whether it is accessed by mobile phone, but as long as the browser prohibits JS from running, it can still be accessed normally. But maybe this will make it difficult for some newbies.



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!