根据浏览器Agent识别用户的操作系统,从而确定用户设备是手机还是PC
$uAgent = $_SERVER['HTTP_USER_AGENT']; $osPat = "mozilla|m3gate|winwap|openwave|Windows NT|Windows 3.1|95|Blackcomb|98|ME|X Window|ubuntu|Longhorn|AIX|Linux|AmigaOS|BEOS|HP-UX|OpenBSD|FreeBSD|NetBSD|OS\/2|OSF1|SUN"; if(preg_match("/($osPat)/i", $uAgent )) //winwap 模拟WAP手机上网的一个浏览器; openwave|后面为各pc操作系统 { echo "电脑访问"; } else { echo "手机访问"; } echo '<br/>'.$uAgent;