Home > Backend Development > PHP Tutorial > PHP determines whether the accessed website is android, ios or wp_PHP tutorial

PHP determines whether the accessed website is android, ios or wp_PHP tutorial

WBOY
Release: 2016-07-13 09:52:00
Original
898 people have browsed it

php determines whether the website is accessed by android, ios or wp

The following is an example of how to determine whether the website is accessed by php android, ios or wp. I hope it will be useful to you. Friends it will be helpful.

In php, you can use $_SERVER['HTTP_USER_AGENT'] to distinguish whether it is an android, ios or wp request. Specifically, you can use the following code to achieve it:

$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 add a piece of js code to the head of the web page and the effect will be the same.

In this way, as long as you access the website from your mobile phone, you will automatically reach the mobile version of the website

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1010441.htmlTechArticleVisit the website to determine whether it is android, ios or wp. Below is a section of php to determine whether it is android, ios or wp. WP website access example, very practical, I hope it will be useful to all my friends...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template