This article is an example of how PHP simply judges the iphone, IPad, Android, and PC devices. Share to everyone for your reference, specific as follows:
Because the work needs we need to know what kind of the user visited my site, now a lot of mobile devices, the following we look at the small compiled a section of PHP to determine the iphone, IPad, Android, PC device examples.
I will use the Windows system device as a PC, after all, blog for Chinese users, most of the home device or Windows system.
The principle is to determine the user AGENT submitted by the browser, the code is as follows:
<?php
//Get USER AGENT
$agent = strtolower ($_server[' http_user_agent '));
Analysis 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 manipulated as follows, the code is as follows:
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;
}
More interested in PHP related content readers can view the site topics: "PHP Network Programming Skills Summary", "Php Curl Usage Summary", "PHP Socket Usage Summary", "PHP Regular Expression Usage summary", "PHP string (String) Usage Summary", " PHP array Operation techniques Encyclopedia, "PHP Mathematical Calculation Skills Summary", "PHP object-oriented Programming Introductory Course", "PHP Data structure and algorithm tutorial", "PHP Programming algorithm Summary" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design.