Php judges whether it is android, ios, or wp to visit website _ PHP Tutorial

Source: Internet
Author: User
Php checks whether the website is accessed by android, ios, or wp. Php judges whether it is android, ios, or wp to visit the website. The following section provides an example of php to determine whether it is android, ios, or wp to visit the website, it is very practical. I hope my friends can use php to determine whether to visit the website for android, ios, or wp.

Next, let's organize a php website access example to determine whether it is android, ios, or wp. it is very practical and helpful to all of you.

In php, you can use $ _ SERVER ['http _ USER_AGENT '] to distinguish between android, ios, and wp Requests. you can use the following code to implement this function:

$ 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 add a js code in the webpage header to achieve the same effect.

In this way, as long as the mobile phone accesses the website, it will automatically go to the mobile phone version website.

In the following article, I will organize a php website access example for you to determine whether it is android, ios, or wp. it is very practical and I hope to give it to your friends...

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.