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; } |