Home >Backend Development >PHP Tutorial >PHP detection mobile device class mobile detection usage example_PHP tutorial
Currently, it is normal for a website to have multiple versions, such as PC version, 3G version, mobile version, etc. Depending on the browsing device we need to be directed to different versions. Not only that, we sometimes need to load different CSS according to different clients, so we need to be able to detect the browsing device, SO, we need to use the "mobile detection" class library.
"mobile detection" is a lightweight mobile device detection PHP class library that uses a combination of User-Agent strings in specific HTTP headers to detect mobile client environments. Note that mobile detection is only a server-side (PHP) detection tool and cannot replace responsive web design or any other form of client-side function detection.
mobile detection class library download address: https://github.com/serbanghita/Mobile-Detect
Example 1: Redirect to other versions based on device
When we use a mobile device to browse a website, we need to be directed to the mobile version of the website. First, include the file Mobile_Detect.php with detection function into the web page or home page. Now let’s browse www.uncletoo.com When the website is redirected to m.uncletoo.com:
Example 2: Load different resources according to different devices
As mentioned above, we can also load different CSS files according to different browsing devices. For example:
Note that mobile detection is a mobile device detection platform. With the advancement of technology, different devices will appear, so you need to update the class library at any time to ensure the accuracy of detection.