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));
}
posted @ 2025-03-25 18:13  幽暗天琴  阅读(17)  评论(0)    收藏  举报