Simplest way to detect a mobile device in PHP

后端 未结 15 2536
别跟我提以往
别跟我提以往 2020-11-22 05:12

What is the simplest way to tell if a user is using a mobile device to browse my site using PHP?

I have come across many classes that you can use but I was hoping fo

15条回答
  •  难免孤独
    2020-11-22 05:33

    PHP device detection from 51Degrees.com does exactly what you want - detects mobile devices and various properties associated with detected devices. It is simple to use and requires no maintenance. Set up is done in 4 easy steps:

    1. Download the Zip file from http://sourceforge.net/projects/fiftyone/.
    2. Unzip the file into a directory in your PHP server.
    3. Then add the following code to your PHP page:
    4. require_once 'path/to/core/51Degrees.php';
      require_once 'path/to/core/51Degrees_usage.php';
      
    5. All available device information will be contained in $_51d array:
    6. if ($_51d['IsMobile'])
      {
          //Start coding for a mobile device here.
      }
      

    51Degrees device detector does not use regular expressions for detections. Only important parts of HTTP headers are used to match devices. Which makes this solution the fastest (5 000 000 detections per second on mediocre hardware) and most accurate (99.97% accuracy) as hundreds of new devices are added to the database weekly (Supported device types include consoles, smart TVs, e-readers, tablets and more).

    Software is open source distributed under Mozilla Public License 2 and compatible with commercial and open source projects. As a bonus 51Degrees solution also contains a complementary PHP image optimiser that can automatically resize images for mobile devices.

    By default 51Degrees PHP device detector uses Lite data file which is free and contains over 30000 devices and 50 properties for each device. Lite file is updated once every 3 month. If you want to have a higher level of details about requesting mobile devices, then Premium and Enterprise data files are available. Premium contains well over 70000 devices and 100 properties for each device with weekly updates. Enterprise is updated daily and contains over 150000 devices with 150 properties for each.

    Full list of device properties.
    Compare data files.

提交回复
热议问题