PHP's Way of judging iphone, IPad, Android, PC devices

Source: Internet
Author: User

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

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

The code is as follows Copy Code

<?php
Get the user AGENT
$agent = Strtolower ($_server[' http_user_agent '));

Analyze data
$is _pc = (Strpos ($agent, ' Windows NT '))? 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";
}
?>

If you only judge whether the iphone device can be operated as follows

  code is as follows copy code

function Get_device_type () {
  $agent = strtolower ($_server[' http_user_agent '));
  $type = ' other ';
 if Strpos ($agent, ' iphone ') | | | strpos ($agent, ' ipad ')  ) {
  $type = ' iOS ';
 }
 if ($agent, ' Android ') Strpos {
  $type = ' Android ';
 }
 return $type;
}

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.