Use PHP to determine iphone, IPad, Android, PC devices

Source: Internet
Author: User
Tags delete cache

Home that big picture really is a more headache problem

On the PC display is no problem, but to the phone will exceed the page a large section, if you do adaptive, the image will be forced compression

Helpless can only use the Wp_is_mobile () function to hide the picture on the phone, but this function seems to not work on the ipad

High-resolution devices, such as the ipad Air, are fine, but they can be disastrous on low-resolution devices such as the iPad2.

So I decided to write a code to solve the problem.

Judging the Code

I will use the Windows system of the device as a PC, after all, blog for Chinese users, most of the home devices still use the Windows system

The principle is to determine the user AGENT submitted by the browser

123456789101112131415161718192021222324 <?php//Get user AGENT$agent = strtolower($_server[' http_user_agent ']); //Analysis Data $is _pc = (strpos ( $agent , ' Windows NT ' Span class= "Crayon-sy" >) ? true : false;    $is _iphone = (strpos ( $agent , ' iphone ' ? true : false;    $is _ipad = (strpos ( $agent , ' ipad ' ? true : false;    $is _android = (strpos($agent, ' Android ') ?    true : false; //Output data if($is _pc){ echo "This is PC";     }   if($is _iphone){ echo "This is the iphone";     }   if($is _ipad){ echo "This is the ipad";     }   if($is _android){ echo "This is Android";     }   ?>

How to use

You can replace the Echo statement with the one you want to output on each device.

If you do not need to set the device separately, remove the if code corresponding to it

Prohibit WP Super cache cache home

Since WP Super cache caches the home page

Cause the judgment code to fail, we must prohibit it from caching the home page

1. Enter Settings-wp Super Cache

2. Advanced options, find "accepted filenames and denied URIs" at the bottom

3. Check the homepage (is_home)

4, click the Save button, then select the top content options, click "Delete Cache" can

5, if necessary, enter the pre-cache option, click "Preload Cache Now"

Use PHP to determine iphone, IPad, Android, PC devices

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.