PHP获取用户设备信息判断是苹果还是安卓还是其他:$_SERVER['HTTP_USER_AGENT']
$temUrl = $temApp['android'];
if (dstrpos($_SERVER['HTTP_USER_AGENT'], ['iphone', 'ipad', 'ipod', 'mac', 'ios', 'playbook'])) {
$temUrl = $temApp['ios'];
} else if (dstrpos($_SERVER['HTTP_USER_AGENT'], ['android', 'Windows'])) {
$temUrl = $temApp['android'];
}
redirect($temUrl);die;
//自定义函数:
//dstrpos函数用于检查给定的字符串$string中是否包含数组$arr中的任意一个子字符串。如果包含,则返回true,否则返回false
function dstrpos($string, $arr)
{
if (!empty($string)) {
foreach ((array) $arr as $_var_136) {
if (strpos(strtolower($string), $_var_136) !== false) {
return true;
}
}
}
return false;
}
//跳转页面
function redirect($url = '/', $code = '')
{
if ($code == 301) {
header("HTTP/1.1 301 Moved Permanently");
}
exit(header("location:" . $url));
}
每天进步一点点

浙公网安备 33010602011771号