Because the job needs us to know what it is. The user visited my website, now there are many kinds of mobile devices, let's look at the small compilation of a section of PHP to determine the iphone, IPad, Android, PC device examples.
Note: This code of the PC system for Windows
The principle is to determine the user AGENT submitted by the browser
<?php
Get the user AGENT
$agent = Strtolower ($_server[' http_user_agent ');
Make judgments
$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;
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 determine whether the iphone device can be operated as follows, the code is as follows:
<?php
function Get_device_type () {
$agent = Strtolower ($_server[' http_user_agent ');
$type = ' other ';
if (Strpos ($agent, ' iphone ') | | strpos ($agent, ' ipad '))
{
$type = ' iOS ';
}
if (Strpos ($agent, ' Android '))
{
$type = ' Android ';
}
return $type;
}
?>
PHP's approach to judging iphone, IPad, Android, and PC devices