微信端与移动端设备的判断
用户访问服务器时,利用PHP的超级全局变量$_SERVER数组中字段['HTTP_USER_AGENT'] 获取访问用户的所有信息
<?php
echo $_SERVER['HTTP_USER_AGENT'];
?>
1. 微信端设备的判断
<?php if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false): ?>
<?php
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($agent, 'android')):
$type = 'android';endif;?>
3. 苹果设备的判断
<?php
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($agent, 'iphone')):
$type = 'ios';endif;?>
4. iPad设备的判断
<?php
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
if(strpos($agent, 'ipad')):
$type = 'ipad';endif;?>
5.所有的设备判断
<?php
$agent = strtolower($_SERVER['HTTP_USER_AGENT']);
$type = 'pc';
if(strpos($agent, 'ipad')):
$type = 'ipad';
endif;
if(strpos($agent, 'android')):
$type = 'android';
endif;
if(strpos($agent, 'ios')):
$type = 'ios';
endif;
if(isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessenger') !== false):
$type = 'MicroMessenger';
endif;
echo $type;
?>