36

尝试仅使用 PHP 检测用户的浏览器,$_SERVER['HTTP_USER_AGENT'] 是一种可靠的方法吗?我应该选择get_browser功能吗?你觉得哪一个能带来更精确的结果?

如果此方法实用,是否不建议将其用于输出相关的 CSS 链接,例如:

if(stripos($_SERVER['HTTP_USER_AGENT'],"mozilla")!==false)
   echo '<link type="text/css" href="mozilla.css" />';

我注意到了这个问题,但是我想澄清这是否有利于面向 CSS 的检测。

更新: 一些非常可疑的事情:我echo $_SERVER['HTTP_USER_AGENT'];在 IE 7 上试过,这就是它的输出:

Mozilla/4.0(兼容;MSIE 7.0;Windows NT 6.0;SLCC1;.NET CLR 2.0.50727;Media Center PC 5.0;.NET CLR 3.5.30729;.NET CLR 3.0.30618)

Safari 也给了一些奇怪的东西,里面有“mozilla”。是什么赋予了?

4

11 回答 11

70

检查此代码,我发现这很有用。不要检查 Mozilla,因为大多数浏览器都使用它作为用户代理字符串

if(strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE)
   echo 'Internet explorer';
 elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE) //For Supporting IE 11
    echo 'Internet explorer';
 elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Firefox') !== FALSE)
   echo 'Mozilla Firefox';
 elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE)
   echo 'Google Chrome';
 elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera Mini') !== FALSE)
   echo "Opera Mini";
 elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE)
   echo "Opera";
 elseif(strpos($_SERVER['HTTP_USER_AGENT'], 'Safari') !== FALSE)
   echo "Safari";
 else
   echo 'Something else';
于 2013-03-25T05:56:10.100 回答
21

使用现有的方法(即get_browser)可能比自己编写一些东西更好,因为它有(更好的)支持并且将使用更新的版本进行更新。那里可能还有可用的库,用于以可靠的方式获取浏览器 ID。

解码$_SERVER['HTTP_USER_AGENT']是很困难的,因为很多浏览器都有非常相似的数据,并且倾向于(错误地)使用它来谋取自己的利益。但是如果你真的想解码它们,你可以使用这个页面上的信息来获取所有可用的代理 ID。此页面还显示您的示例输出确实属于 IE 7。有关代理 id 本身中的字段的更多信息可以在此页面上找到,但正如我所说,浏览器已经倾向于使用它来获取自己的利益,它可能在(略)其他格式。

于 2010-02-13T13:28:00.720 回答
7

用户代理可以被伪造,最好不要依赖用户代理字符串,如果您只想检测方向,则可以使用 CSS3 媒体查询(您可以探索著名的响应式框架引导程序的 CSS 以检查如何处理使用 CSS 的方向部分)

这是小CSS:

    @media only screen and (max-width: 999px) {
     /* rules that only apply for canvases narrower than 1000px */
    }

    @media only screen and (device-width: 768px) and (orientation: landscape) {
    /* rules for iPad in landscape orientation */
    }

    @media only screen and (min-device-width: 320px) and (max-device-width: 480px) {
    /* iPhone, Android rules here */
    }    

阅读更多:关于 CSS 方向检测

或者您可以使用 JavaScript 找到方向:

    // Listen for orientation changes
    window.addEventListener("orientationchange", function() {
        // Announce the new orientation number
        alert(window.orientation);
    }, false);

阅读更多:关于使用 JS 检测方向

最后,如果您真的想使用用户代理字符串,那么这段代码将对您有很大帮助,几乎在每个浏览器上都能正常工作:

<?php
class BrowserDetection {

    private $_user_agent;
    private $_name;
    private $_version;
    private $_platform;

    private $_basic_browser = array (
       'Trident\/7.0' => 'Internet Explorer 11',
    'Beamrise' => 'Beamrise',
    'Opera' => 'Opera',
    'OPR' => 'Opera',
    'Shiira' => 'Shiira',
    'Chimera' => 'Chimera',
    'Phoenix' => 'Phoenix',
    'Firebird' => 'Firebird',
    'Camino' => 'Camino',
    'Netscape' => 'Netscape',
    'OmniWeb' => 'OmniWeb',
    'Konqueror' => 'Konqueror',
    'icab' => 'iCab',
     'Lynx' => 'Lynx',
    'Links' => 'Links',
    'hotjava' => 'HotJava',
    'amaya' => 'Amaya',
    'IBrowse' => 'IBrowse',
    'iTunes' => 'iTunes',
    'Silk' => 'Silk',
    'Dillo' => 'Dillo', 
    'Maxthon' => 'Maxthon',
    'Arora' => 'Arora',
    'Galeon' => 'Galeon',
    'Iceape' => 'Iceape',
    'Iceweasel' => 'Iceweasel',
    'Midori' => 'Midori',
    'QupZilla' => 'QupZilla',
    'Namoroka' => 'Namoroka',
    'NetSurf' => 'NetSurf',
    'BOLT' => 'BOLT',
    'EudoraWeb' => 'EudoraWeb',
    'shadowfox' => 'ShadowFox',
    'Swiftfox' => 'Swiftfox',
    'Uzbl' => 'Uzbl',
    'UCBrowser' => 'UCBrowser',
    'Kindle' => 'Kindle',
    'wOSBrowser' => 'wOSBrowser',
     'Epiphany' => 'Epiphany', 
    'SeaMonkey' => 'SeaMonkey',
    'Avant Browser' => 'Avant Browser',
    'Firefox' => 'Firefox',
    'Chrome' => 'Google Chrome',
    'MSIE' => 'Internet Explorer',
    'Internet Explorer' => 'Internet Explorer',
     'Safari' => 'Safari',
    'Mozilla' => 'Mozilla'  
    );

     private $_basic_platform = array(
        'windows' => 'Windows', 
     'iPad' => 'iPad', 
      'iPod' => 'iPod', 
    'iPhone' => 'iPhone', 
     'mac' => 'Apple', 
    'android' => 'Android', 
    'linux' => 'Linux',
    'Nokia' => 'Nokia',
     'BlackBerry' => 'BlackBerry',
    'FreeBSD' => 'FreeBSD',
     'OpenBSD' => 'OpenBSD',
    'NetBSD' => 'NetBSD',
     'UNIX' => 'UNIX',
    'DragonFly' => 'DragonFlyBSD',
    'OpenSolaris' => 'OpenSolaris',
    'SunOS' => 'SunOS', 
    'OS\/2' => 'OS/2',
    'BeOS' => 'BeOS',
    'win' => 'Windows',
    'Dillo' => 'Linux',
    'PalmOS' => 'PalmOS',
    'RebelMouse' => 'RebelMouse'   
     ); 

    function __construct($ua = '') {
        if(empty($ua)) {
           $this->_user_agent = (!empty($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:getenv('HTTP_USER_AGENT'));
        }
        else {
           $this->_user_agent = $ua;
        }
       }

    function detect() {
        $this->detectBrowser();
        $this->detectPlatform();
        return $this;
    }

    function detectBrowser() {
     foreach($this->_basic_browser as $pattern => $name) {
        if( preg_match("/".$pattern."/i",$this->_user_agent, $match)) {
            $this->_name = $name;
             // finally get the correct version number
            $known = array('Version', $pattern, 'other');
            $pattern_version = '#(?<browser>' . join('|', $known).')[/ ]+(?<version>[0-9.|a-zA-Z.]*)#';
            if (!preg_match_all($pattern_version, $this->_user_agent, $matches)) {
                // we have no matching number just continue
            }
            // see how many we have
            $i = count($matches['browser']);
            if ($i != 1) {
                //we will have two since we are not using 'other' argument yet
                //see if version is before or after the name
                if (strripos($this->_user_agent,"Version") < strripos($this->_user_agent,$pattern)){
                    @$this->_version = $matches['version'][0];
                }
                else {
                    @$this->_version = $matches['version'][1];
                }
            }
            else {
                $this->_version = $matches['version'][0];
            }
            break;
        }
       }
   }

    function detectPlatform() {
      foreach($this->_basic_platform as $key => $platform) {
            if (stripos($this->_user_agent, $key) !== false) {
                $this->_platform = $platform;
                break;
            } 
      }
    }

   function getBrowser() {
      if(!empty($this->_name)) {
           return $this->_name;
      }
   }        

   function getVersion() {
       return $this->_version;
    }

    function getPlatform() {
       if(!empty($this->_platform)) {
          return $this->_platform;
       }
    }

    function getUserAgent() {
        return $this->_user_agent;
     }

     function getInfo() {
         return "<strong>Browser Name:</strong> {$this->getBrowser()}<br/>\n" .
        "<strong>Browser Version:</strong> {$this->getVersion()}<br/>\n" .
        "<strong>Browser User Agent String:</strong> {$this->getUserAgent()}<br/>\n" .
        "<strong>Platform:</strong> {$this->getPlatform()}<br/>";
     }
}  

$obj = new BrowserDetection();

echo $obj->detect()->getInfo();

上面的代码几乎适用于所有浏览器,我希望它对你有所帮助。

于 2015-02-18T14:06:11.113 回答
5
class Browser { 
    /** 
    Figure out what browser is used, its version and the platform it is 
    running on. 

    The following code was ported in part from JQuery v1.3.1 
    */ 
    public static function detect() { 
        $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']); 

        // Identify the browser. Check Opera and Safari first in case of spoof. Let Google Chrome be identified as Safari. 
        if (preg_match('/opera/', $userAgent)) { 
            $name = 'opera'; 
        } 
        elseif (preg_match('/webkit/', $userAgent)) { 
            $name = 'safari'; 
        } 
        elseif (preg_match('/msie/', $userAgent)) { 
            $name = 'msie'; 
        } 
        elseif (preg_match('/mozilla/', $userAgent) && !preg_match('/compatible/', $userAgent)) { 
            $name = 'mozilla'; 
        } 
        else { 
            $name = 'unrecognized'; 
        } 

        // What version? 
        if (preg_match('/.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/', $userAgent, $matches)) { 
            $version = $matches[1]; 
        } 
        else { 
            $version = 'unknown'; 
        } 

        // Running on what platform? 
        if (preg_match('/linux/', $userAgent)) { 
            $platform = 'linux'; 
        } 
        elseif (preg_match('/macintosh|mac os x/', $userAgent)) { 
            $platform = 'mac'; 
        } 
        elseif (preg_match('/windows|win32/', $userAgent)) { 
            $platform = 'windows'; 
        } 
        else { 
            $platform = 'unrecognized'; 
        } 

        return array( 
            'name'      => $name, 
            'version'   => $version, 
            'platform'  => $platform, 
            'userAgent' => $userAgent 
        ); 
    } 
} 


$browser = Browser::detect(); 
于 2012-08-14T17:54:24.430 回答
3

如果 stripos($_SERVER['HTTP_USER_AGENT'],"mozilla")!==false)

这不是一个有用的测试,几乎每个浏览器都将自己标识为 Mozilla。

$_SERVER['HTTP_USER_AGENT'] 是一种可靠的方法吗?

不。

我应该选择 get_browser 功能吗?

不。

服务器端的浏览器嗅探是一场失败的游戏。除了尝试解析 UA 字符串的所有问题、存在的浏览器、晦涩的浏览器以及标题根本不存在的可能性之外,如果您为不同的浏览器返回不同的页面内容,则必须将Vary标题设置为include User-Agent,否则缓存代理可能会将错误版本的页面返回到错误的浏览器。

但是,如果您添加Vary: User-AgentIE 损坏的缓存代码,就会感到困惑并每次都重新加载页面。所以你赢不了。

如果您必须进行浏览器嗅探,则可以在客户端使用 JavaScript,特别是在 IE 的情况下,使用条件注释。幸运的是,它是支持条件注释的 IE,因为这是您经常需要解决方法的一个浏览器。(有关最常见的策略,请参阅 scunliffe 的回答。)

于 2010-02-13T13:39:57.763 回答
2

旧帖子仍然出现在谷歌中。get_browser() 是最好的解决方案,但编辑 php.ini 可能是不可能的。根据这篇文章,您不能 ini_set browscap 属性。那么还剩下什么?phpbrowscap似乎完成了工作。文档不是很好,所以如果您不希望它自动更新(默认为开启),那么您需要设置

$bc->updateMethod = phpbrowscap\Browscap::UPDATE_LOCAL;
$bc->localFile = __DIR__ . "/php_browscap.ini";
于 2013-08-16T00:42:36.947 回答
2

我注意到,真正的浏览器名称总是在最后一个之后(parentheses),除了 IE,在最后一个之后没有浏览器名称(parentheses)。我想知道是否只有在最后一个之后阅读)才能提高准确性。

您可能会在不同的用户代理中注意到这一点:

谷歌浏览器

苹果浏览器

火狐

边缘

IE(括号后没有定义浏览器的例外)

例子:

$userBrowser = (!empty($_SERVER['HTTP_USER_AGENT'])?$_SERVER['HTTP_USER_AGENT']:getenv('HTTP_USER_AGENT'));
$userBrowser = explode(')', $userBrowser);
$userBrowser = $userBrowser[count($userBrowser)-1];

echo $userBrowser; //this has many inaccurate browsers stripped out

一个完整的功能:

function getUserBrowser(){
  $fullUserBrowser = (!empty($_SERVER['HTTP_USER_AGENT'])? 
  $_SERVER['HTTP_USER_AGENT']:getenv('HTTP_USER_AGENT'));
  $userBrowser = explode(')', $fullUserBrowser);
  $userBrowser = $userBrowser[count($userBrowser)-1];

  if((!$userBrowser || $userBrowser === '' || $userBrowser === ' ' || strpos($userBrowser, 'like Gecko') === 1) && strpos($fullUserBrowser, 'Windows') !== false){
    return 'Internet-Explorer';
  }else if((strpos($userBrowser, 'Edge/') !== false || strpos($userBrowser, 'Edg/') !== false) && strpos($fullUserBrowser, 'Windows') !== false){
    return 'Microsoft-Edge';
  }else if(strpos($userBrowser, 'Chrome/') === 1 || strpos($userBrowser, 'CriOS/') === 1){
    return 'Google-Chrome';
  }else if(strpos($userBrowser, 'Firefox/') !== false || strpos($userBrowser, 'FxiOS/') !== false){
    return 'Mozilla-Firefox';
  }else if(strpos($userBrowser, 'Safari/') !== false && strpos($fullUserBrowser, 'Mac') !== false){
    return 'Safari';
  }else if(strpos($userBrowser, 'OPR/') !== false && strpos($fullUserBrowser, 'Opera Mini') !== false){
    return 'Opera-Mini';
  }else if(strpos($userBrowser, 'OPR/') !== false){
    return 'Opera';
  }
  return false;
}

echo 'browser detect: '.getUserBrowser();

我还在 chrome、edge 和 firefox 开发人员上对此进行了测试,它运行正常。(虽然我还没有测试过这些浏览器的旧版本)

于 2020-01-24T13:23:12.727 回答
2

我发现的大多数 PHP 包似乎都非常好,但我找不到一个能满足我所有需要的好包,所以我构建了一个 Laravel 助手来组合其中的 3 个。

以下是软件包:

詹塞格斯/经纪人

哪个浏览器/解析器

cbschuld/browser.php

这是我的功能:

function browser($userAgent)
{
    $agent = new \Jenssegers\Agent\Agent();
    $agent->setUserAgent($userAgent);

    $result = new \WhichBrowser\Parser($userAgent);

    $browser = new \Browser($userAgent);

    return new class($agent, $result, $browser)
    {
        public function __construct($agent, $result, $browser)
        {
            $this->agent = $agent;
            $this->result = $result;
            $this->browser = $browser;
        }
        public function device()
        {
            return $this->agent->device() ?: $this->result->device->toString() ?: $this->browser->getPlatform();
        }
        public function browser()
        {
            return $this->agent->browser() ?: $this->result->browser->name ?: $this->browser->getBrowser();
        }
        public function platform()
        {
            return $this->agent->platform() ?: $this->result->os->name ?: $this->browser->getPlatform();
        }
        public function isMobile()
        {
            return $this->agent->isPhone() ?: $this->result->isType('mobile') ?: $this->browser->isMobile();
        }
        public function isTablet()
        {
            return $this->result->isType('tablet') ?: $this->browser->isTablet();
        }
        public function isDesktop()
        {
            return $this->agent->isDesktop() ?: $this->result->isType('desktop') ?: (! $this->browser->isMobile() && ! $this->browser->isTablet());
        }
        public function isRobot()
        {
            return $this->agent->isRobot() ?: $this->browser->isRobot();
        }
    };

以下是如何使用它:

$browser = browser($userAgent);

$browser->device();
$browser->platform();
$browser->browser();
$browser->isMobile();
$browser->isTablet();
$browser->isDesktop();
$browser->isRobot();
于 2020-06-10T16:42:50.127 回答
1

我认为依赖 userAgent 有点弱,因为它可以(并且经常)被伪造。

如果您只想为 IE 提供 CSS,请使用条件注释。

<link type="text/css" rel="stylesheet" href="styles.css"/><!--for all-->
<!--[if IE]>
  <link type="text/css" rel="stylesheet" href="ie_styles.css"/>
<![endif]-->

或者如果你只想要一个用于 IE6:

<!--[if IE 6]>
  <link type="text/css" rel="stylesheet" href="ie6_styles.css"/>
<![endif]-->

由于它的评论被浏览器忽略...除了 IE 如果 if 测试与当前浏览器匹配则加载它。

于 2010-02-13T13:32:55.770 回答
0
Check This Code :      
   <?php     

class OS_BR{    
private $agent = "";
private $info = array();

function __construct(){
    $this->agent = isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : NULL;
    $this->getBrowser();
    $this->getOS();
}     
function getBrowser(){     
    $browser = array("Navigator"            => "/Navigator(.*)/i",
                     "Firefox"              => "/Firefox(.*)/i",
                     "Internet Explorer"    => "/MSIE(.*)/i",
                     "Google Chrome"        => "/chrome(.*)/i",
                     "MAXTHON"              => "/MAXTHON(.*)/i",
                     "Opera"                => "/Opera(.*)/i",
                     );
    foreach($browser as $key => $value){
        if(preg_match($value, $this->agent)){
            $this->info = array_merge($this->info,array("Browser" => $key));
            $this->info = array_merge($this->info,array(
              "Version" => $this->getVersion($key, $value, $this->agent)));
            break;
        }else{
            $this->info = array_merge($this->info,array("Browser" => "UnKnown"));
            $this->info = array_merge($this->info,array("Version" => "UnKnown"));
        }
    }
    return $this->info['Browser'];
}
function getOS(){
    $OS = array("Windows"   =>   "/Windows/i",
                "Linux"     =>   "/Linux/i",
                "Unix"      =>   "/Unix/i",
                "Mac"       =>   "/Mac/i"
                );

    foreach($OS as $key => $value){
        if(preg_match($value, $this->agent)){
            $this->info = array_merge($this->info,array("Operating System" => $key));
            break;
        }
    }
    return $this->info['Operating System'];
}

function getVersion($browser, $search, $string){
    $browser = $this->info['Browser'];
    $version = "";
    $browser = strtolower($browser);
    preg_match_all($search,$string,$match);
    switch($browser){
        case "firefox": $version = str_replace("/","",$match[1][0]);
        break;

        case "internet explorer": $version = substr($match[1][0],0,4);
        break;

        case "opera": $version = str_replace("/","",substr($match[1][0],0,5));
        break;

        case "navigator": $version = substr($match[1][0],1,7);
        break;

        case "maxthon": $version = str_replace(")","",$match[1][0]);
        break;

        case "google chrome": $version = substr($match[1][0],1,10);
    }
    return $version;
}

function showInfo($switch){
    $switch = strtolower($switch);
    switch($switch){
        case "browser": return $this->info['Browser'];
        break;

        case "os": return $this->info['Operating System'];
        break;

        case "version": return $this->info['Version'];
        break;

        case "all" : return array($this->info["Version"], 
          $this->info['Operating System'], $this->info['Browser']);
        break;

        default: return "Unkonw";
        break;

    }
}
 }    


$obj = new OS_BR();

echo $obj->showInfo('browser');

echo $obj->showInfo('version');

echo $obj->showInfo('os');

echo "<pre>".print_r($obj->showInfo("all"),true)."</pre>"; 

 ?>
于 2015-02-18T12:44:43.203 回答
0

@Ekramul Hoque 走在正确的轨道上,但他的回答有几个缺陷。

首先,我将从 Edge 开始,因为 Internet ExplorerEdge的任何 UA 中都不包含该术语。

if(strpos($_SERVER['HTTP_USER_AGENT'], 'Edge') !== FALSE) {
  echo '<link type="text/css" href="ms.css" />';

然后,继续向后工作,因为早期版本的 IE 没有使用该Trident引擎,因此不会将其包含在他们的 UA 中。

} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident') !== FALSE) {
  echo '<link type="text/css" href="ms.css" />';
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') !== FALSE) {
  echo '<link type="text/css" href="ms.css" />';

我们接下来需要针对 iOS 浏览器,以便后续查询不会干扰这个。所有 iOS 浏览器都使用 webkit,但 Opera Mini 除外,它从远程服务器而不是设备进行渲染。这意味着我们可以针对 UA 中的操作系统,iOS并排除包含Opera.

} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'iOS') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Opera') !== FALSE {
  echo '<link type="text/css" href="webkit.css" />';

接下来,继续使用 Firefox 浏览器。虽然使用 Firefox 作为搜索词会起作用,但它只能识别 Firefox 浏览器,而不是基于 Firefox 的浏览器。FirefoxGecko在其 UA 中包含 Gecko 是它使用的引擎,因此我们可以定位它。通过使用Gecko,我们可以识别所有运行在 Gecko 引擎(即 SeaMonkey)上的浏览器。但是,许多浏览器like Gecko出于兼容性原因使用该术语,因此我们必须确保匹配Gecko而不是like Gecko.

} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Gecko') && !strpos($_SERVER['HTTP_USER_AGENT'], 'like Gecko') !== FALSE) {
  echo '<link type="text/css" href="moz.css" />';

继续我们将识别 Opera 浏览器。Opera 使用Presto引擎到 v12 结束。从 v15 开始,他们开始使用 Chrome 等 Blink 引擎。v12 和更早版本在 UA 中包含 v15+ 没有的两个唯一词--OperaPresto. 您可以针对他们中的任何一个,因为他们总是一起出现。对于 v15,Opera 开始OPR在 UA 中使用。

} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Presto') !== FALSE) {
  echo '<link type="text/css" href="o.css" />';
} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'OPR') !== FALSE) {
  echo '<link type="text/css" href="normal.css" />';

接下来是Safari。Safari 使用 AppleWebKit 作为其渲染引擎,但我们不能只针对它,因为出于兼容性原因,Chrome 也包含这两者AppleWebKit和它的 UA。Safari因此,我们需要搜索AppleWebKit而不是Chrome

} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'AppleWebKit') && !strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE) {
  echo '<link type="text/css" href="webkit.css" />';

最后,我们进入 Chrome。Chrome 使用 AppleWebKit 直到 v27。随着 v28 版本的发布,他们切换到了 Blink 引擎。我们可以同时针对这两个引擎,但这需要大量代码。由于 Chrome 现在几乎是 v70,我们将只搜索,Chrome因为极不可能有人仍在运行 Chrome 的 webkit 版本。

} elseif (strpos($_SERVER['HTTP_USER_AGENT'], 'Chrome') !== FALSE {
  echo '<link type="text/css" href="normal.css" />';

最后但并非最不重要的是,你的后备/其他。

} else {
  echo '<link type="text/css" href="normal.css" />';
}

现在,我使用引用供应商前缀的 css 文件来定位这里。根据需要随意调整它,让它做你需要做的事情。我希望这会有所帮助。

于 2018-04-20T21:42:40.190 回答