PHP判断客户端浏览器类型

让人想犯罪 __ 提交于 2020-08-06 19:46:20

代码如下

<?php
/**
 * 判断浏览器名称和版本
 */
function get_user_browser()
{
    if (empty($_SERVER['HTTP_USER_AGENT'])) {
        return 'error!';
    }
    if ((strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') == false) && (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE)) {
        return 'Internet Explorer 11.0';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 10.0') != false) {
        return 'Internet Explorer 10.0';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9.0') != false) {
        return 'Internet Explorer 9.0';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 8.0') != false) {
        return 'Internet Explorer 8.0';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 7.0') != false) {
        return 'Internet Explorer 7.0';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6.0') != false) {
        return 'Internet Explorer 6.0';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') != false) {
        return 'Edge';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], '360SE') != false) {
        return '360SE';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'QQBrowser') != false) {
        return 'QQBrowser';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') != false) {
        return 'Firefox';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') != false) {
        return 'Chrome';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') != false) {
        return 'Safari';
    }
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') != false) {
        return 'Opera';
    }
    //微信浏览器
    if (strpos($_SERVER['HTTP_USER_AGENT'], 'MicroMessage') != false) {
        return 'MicroMessage';
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!