How to determine the built-in browser (implemented through User Agent) and useragent
When developing public accounts, a large part of them is the development of micro-sites. We need to know that the current browser is a built-in browser. How can we determine?
Built-in browser User Agent
To determine the built-in browser, you first need to obtain the User Agent of the built-in browser. After detection by the browser on the iPhone, its User Agent is:
Mozilla/5.0 (iPhone; CPU iPhone OS 6_1_3 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Mobile/10B329 MicroMessenger/5.0.1
So identify the keyword MicroMessenger to determine whether the browser is built in.
JavaScript-based judgment
function is_weixin(){
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
return true;
} else {
return false;
}
}
PHP-based judgment
function is_weixin(){
if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false ) {
return true;
}
return false;
}
How can I use php to redirect a built-in browser to another browser on the mobile phone?
When we were working on a public platform, we wanted to restrict programs to be browsed in order to prevent our painstaking webapps from being copied. Below is the PHP code that restricts page access only in the browser.
When we were working on a public platform, we wanted to restrict programs to be browsed in order to prevent our painstaking webapps from being copied. Below is the PHP code that restricts page access only in the browser.
<! --? Php <br? --> $ Useragent = $ _ SERVER ['HTTP _ USER_AGENT ']; if (strpos ($ useragent, 'micromessenger') === false) {echo "non-browser access prohibited";} else {echo "browser access allowed";} the above Code is not complete, and Windows phone cannot be used, so modify it:
<! --? Php <br? --> $ Useragent = addslashes ($ _ SERVER ['HTTP _ USER_AGENT ']); if (strpos ($ useragent, 'micromessenger ') ===false & strpos ($ useragent, 'windows Phone ') ==== false) {echo "non-browser access prohibited ";} else {echo "browser access allowed ";}
I did not test the Saipan system. You can obtain HTTP_USER_AGEN to determine.
However, if you think the above method can prevent others from stealing your interface, you will be wrong. If you forge HTTP_USER_AGEN, you will still be able to access it normally. Install a User-Agent Switcher on Google's browser, and you can still access it at will. So I also thought of using JS to determine if it was a mobile phone access, but as long as the browser prohibits JS from running, it can still be accessed normally .. However, it may be difficult for new users.
How to view the browser's User Agent without tools
For example, IE browser
Open IE -- tool -- properties, click the "connection" tab in the pop-up dialog box, and click "LAN Settings ...... View my ......