PHP to determine whether it is Android or iOS or WP access to the site

Source: Internet
Author: User

The following for you to organize a section of PHP to determine whether it is Android or iOS or WP access to the website examples, very practical hope for your friends will help.

In PHP can be used $_server[' http_user_agent ' to distinguish between the Android, iOS or WP request, you can use the following code to achieve:

$userAgent = $_server[' http_user_agent '];

if (Preg_match ("/(Ipod|ipad|iphone)/", $userAgent))

{

Echo ' iOS '; iOS client

}

ElseIf (Preg_match ("/wp/", $userAgent))

{

Echo ' WP '; Winphone Client

}

ElseIf (Preg_match ("/android/i", $userAgent)) {

Echo ' Android '; Android Client

}

Of course I can also in the head of the page with a JS code effect is the same

So as long as the mobile phone access to the site will automatically go to the mobile phone version of the site

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.