In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how to use PHP to detect mobile device mobile detection". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to use PHP to detect mobile device mobile detection".
At present, it is normal for a website to have multiple versions, such as PC version, 3G version, mobile version and so on. We need to direct to different versions according to different browsing devices. Not only that, we sometimes need to load different CSS according to different clients, so we need to be able to detect browsing devices, SO, we need to use the "mobile detection" class library.
"mobile detection" is a lightweight PHP class library for mobile device detection, which detects the mobile client environment by combining User-Agent strings in specific HTTP headers. Note that mobile detection is only a server-side (PHP) detection tool and is not a substitute for responsive Web design or any other form of client-side functional detection.
Download address of mobile detection class library: https://github.com/serbanghita/Mobile-Detect
Example 1: redirect to another version based on the device
When we use a mobile device to browse a website, we need to direct to the mobile version of the website. First, include the file Mobile_Detect.php with detection function in the web page or home page. Now let's redirect to m.uncletoo.com when browsing the www.uncletoo.com website:
The copy code is as follows:
/ * change the path information according to the file location * /
Require_once 'Mobile_Detect.php'
$detect = new Mobile_Detect
If ($detect- > isMobile ()) {
Header ('Location: http://m.uncletoo.com/');
Exit
}
This is a redirect to a mobile website, and there are other forms of redirection below:
/ / all tablet devices
If ($detect- > isTablet ()) {
}
/ / is a mobile but non-tablet device
If ($detect- > isMobile () & &! $detect- > isTablet ()) {
}
/ / IOS system
If ($detect- > isiOS ()) {
}
/ / Android system
If ($detect- > isAndroidOS ()) {
}
/ / WindowsPhone system
If ($detect- > isWindowsPhoneOS ()) {
}
Example 2: load different resources according to different devices
As mentioned above, we can also load different CSS files according to different browsing devices. Such as:
The copy code is as follows:
$detect = new Mobile_Detect
If ($detect- > isMobile () | | $detect- > isTablet ()) {
Echo ""
}
Note that mobile detection is a mobile device detection platform, with the development of technology, different devices will appear, so you need to update the class library at any time in order to ensure the accuracy of detection.
Thank you for reading, the above is the content of "how to use PHP to detect mobile device mobile detection". After the study of this article, I believe you have a deeper understanding of how to use PHP to detect mobile device mobile detection, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 274
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.