This article introduces PHP to determine whether the alexa tool is installed in the User's browser. The principle is very simple. We only need to get the User-Agent character recognition, then you can check whether the alexa toolbar is installed.
As we all know, the alexa toolbar is a commonly used third-party statistical tool for websites. We usually customize the alexa toolbar to allow users to install it. You can click the toolbar content to improve the ranking of the website in alexa. For example, the alexa Toolbar of Hebei News Network.
If we need to force user installation in some necessary php applications, this involves the judgment on whether the alexa toolbar is installed or not. When a browser accesses a webpage, php can obtain User-Agent characters. When a browser with the Alexa Toolbar is used to request a webpage, the User-Agent character will contain more alexa marks. With this feature, you can determine whether your browser has installed the ALEXA toolbar. Use PHP's $ _ SERVER ['HTTP _ USER_AGENT '] to obtain the UA string information of the browser.The following is the code for PHP to determine whether the alexa tool is installed in your browser:
The Code is as follows: |
Copy code |
If (! Preg_match ("# Toolbar # I", $ _ SERVER ['HTTP _ USER_AGENT ']) {showmessage (L ('alexa _ failure'), 'https: // www. bKjia. c0m', 8000 );} |
(Because the User-Agent characters in firefox and ie are different, Alexa Toolbar in firefox and My Toolbar in ie. Therefore, we only need to determine whether the recognition character contains a Toolbar)
Note: how to obtain the alexa toolbar information of IE9
According to the official Microsoft development blog, IE9 uses short User-Agent characters by default and does not append. NET or any other information generated by software or machines to UA strings. Therefore, if you want to obtain whether the IE9 user has installed the alexa toolbar, you must click"Compatibility View"(As shown in)