Typecho实现评论显示操作系统和浏览器标识


源码3871 阅23 评

代码实现评论显示操作系统和浏览器标识

1、首先找到主题根目录,打开 functions.php 文件,在函数区域(不是最顶端)粘贴下面的代码:


// 获取浏览器信息
function getBrowser($agent)
{
    if (preg_match('/MSIE\s([^\s|;]+)/i', $agent, $regs)) {
        $outputer = '';
    } else if (preg_match('/FireFox\/([^\s]+)/i', $agent, $regs)) {
      $str1 = explode('Firefox/', $regs[0]);
$FireFox_vern = explode('.', $str1[1]);
        $outputer = '';
    } else if (preg_match('/Maxthon([\d]*)\/([^\s]+)/i', $agent, $regs)) {
      $str1 = explode('Maxthon/', $agent);
$Maxthon_vern = explode('.', $str1[1]);
        $outputer = '';
    } else if (preg_match('#360([a-zA-Z0-9.]+)#i', $agent, $regs)) {
$outputer = '';
    } else if (preg_match('/Edge([\d]*)\/([^\s]+)/i', $agent, $regs)) {
        $str1 = explode('Edge/', $regs[0]);
$Edge_vern = explode('.', $str1[1]);
        $outputer = '';
    } else if (preg_match('/UC/i', $agent)) {
              $str1 = explode('rowser/',  $agent);
$UCBrowser_vern = explode('.', $str1[1]);
        $outputer = '';
    }  else if (preg_match('/QQ/i', $agent, $regs)||preg_match('/QQBrowser\/([^\s]+)/i', $agent, $regs)) {
                  $str1 = explode('rowser/',  $agent);
$QQ_vern = explode('.', $str1[1]);
        $outputer = '';
    } else if (preg_match('/UBrowser/i', $agent, $regs)) {
              $str1 = explode('rowser/',  $agent);
$UCBrowser_vern = explode('.', $str1[1]);
        $outputer = '';
    }  else if (preg_match('/Opera[\s|\/]([^\s]+)/i', $agent, $regs)) {
        $outputer = '';
    } else if (preg_match('/Chrome([\d]*)\/([^\s]+)/i', $agent, $regs)) {
$str1 = explode('Chrome/', $agent);
$chrome_vern = explode('.', $str1[1]);
        $outputer = '';
    } else if (preg_match('/safari\/([^\s]+)/i', $agent, $regs)) {
         $str1 = explode('Version/',  $agent);
$safari_vern = explode('.', $str1[1]);
        $outputer = '';
    } else{
        $outputer = '';
    }
    echo $outputer;
}
// 获取操作系统信息
function getOs($agent)
{
    $os = false;
 
    if (preg_match('/win/i', $agent)) {
        if (preg_match('/nt 6.0/i', $agent)) {
            $os = ' ';
        } else if (preg_match('/nt 6.1/i', $agent)) {
            $os = ' ';
        } else if (preg_match('/nt 6.2/i', $agent)) {
            $os = ' ';
        } else if(preg_match('/nt 6.3/i', $agent)) {
            $os = ' ';
        } else if(preg_match('/nt 5.1/i', $agent)) {
            $os = ' ';
        } else if (preg_match('/nt 10.0/i', $agent)) {
            $os = ' ';
        } else{
            $os = ' ';
        }
    } else if (preg_match('/android/i', $agent)) {
    if (preg_match('/android 9/i', $agent)) {
            $os = ' ';
        }
    else if (preg_match('/android 8/i', $agent)) {
            $os = ' ';
        }
    else{
            $os = ' ';
    }
    }
    else if (preg_match('/ubuntu/i', $agent)) {
        $os = ' ';
    } else if (preg_match('/linux/i', $agent)) {
        $os = ' ';
    } else if (preg_match('/iPhone/i', $agent)) {
        $os = ' ';
    } else if (preg_match('/mac/i', $agent)) {
        $os = ' ';
    }else if (preg_match('/fusion/i', $agent)) {
        $os = ' ';
    } else {
        $os = ' ';
    }
    echo $os;
}

2、comments.php 中找到合适位置(比如评论作者的后面)添加以下代码:

<!-- 输出操作系统、浏览器版本 -->
<span class="comment-ua">
<?php getOs($comments->agent); ?>&nbspI
<?php getBrowser($comments->agent); ?></span>
<!-- 输出操作系统、浏览器版本 -->

3、css样式自行引用到主题,图标路径自行修改请看css代码
4、然后刷新页面就可以看到UA信息显示出来了

操作系统和浏览器标识UA图标CSS代码下载

此处内容需要评论回复后(审核通过)方可阅读。
最后更新 2023-04-12
评论 ( 23 )
OωO
隐私评论
  1. zed   I

    还怎不知道怎么开启

    7个月前香港回复
  2. 半仙   I

    我也来看看

    1年前浙江省宁波市回复
  3. 晴天!雨天   I

    看看看

    1年前江西省南昌市回复
  4. 云菟   I

    看看隐藏

    2年前四川省回复
  5. SSWIN   I

    踩踩

    2年前台湾省桃园市回复
  6. 苦瓜   I

    这咋用

    2年前山东省青岛市回复
    1. @苦瓜

      教程很详细了

      2年前内蒙古回复
  7. 累了   I

    好棒👍

    2年前安徽省回复
  8. eie4646   I

    好玩

    2年前辽宁省回复
  9. 长卿   I

    看看👀

    2年前安徽省合肥市回复
  10. 可乐   I

    看看

    2年前四川省成都市回复
  11. 寻梦xunm   I

    来偷文章了

    2年前浙江省回复
    1. 2年前广东省回复
  12. 四海   I

    我要看看

    2年前浙江省回复
    1. enah.edu.mx   I
      @四海

      Legal steroids have not brought on any virilization-related side effects in our feminine patients.
      Nevertheless, we recommend buying from a trustworthy model to make sure you are
      getting genuine legal steroid options (instead of a spiked product).
      To guarantee the effectiveness of the authorized steroids we suggest, we assessed the scientific proof supporting every ingredient.

      Legal steroids are produced from one hundred pc all-natural components,
      which is why they're recognized to be safe and cause minimal to no unwanted facet effects.
      The Ultimate Stack is a combination of six different dietary
      supplements designed to help with muscle development, fats loss, and total
      health. We have proof to recommend that Crazy Bulk’s authorized steroids do work, primarily based on our anecdotal experience of
      sufferers trying their supplements. Loopy Bulk additionally
      has thousands of verified customer critiques on third-party platforms and optimistic feedback
      on social media profiles. HGH is a protein hormone that's naturally secreted by the pituitary gland.
      Bodybuilders usually take HGH in exogenous form to increase HGH manufacturing, rising muscle mass and fats loss.
      Though not the most powerful of steroids, Deca is usually
      utilized by bodybuilders to reinforce the gains from other bulking steroids.

      To gauge the general value of every authorized steroid, we thought of elements similar to effectiveness, safety,
      formula transparency, manufacturer reputation, and worth.

      The strongest legal steroid stack includes 2-4 natural dietary supplements that each provide their very own advantages.
      The top steroid stacks are discovered on CrazyBulk web site, and are a combination of legal steroids like Clenbutrol,
      HGH-X2, and D-Bal.
      If you have received the time, nothing will beat an excellent exercise routine and diet!
      As A Substitute of relying on anabolic steroids or different muscle-building supplements, take the time you will need and comply with these fast tips
      for natural steroid alternatives. Don't stop at intense workouts, and stick with a wholesome and balanced food regimen. Out of all of the options on our review of the highest
      legal steroid options, D-Bal works one of the best for the bulking section.
      Whereas the pill accommodates caffeine, it's nothing that individuals who work out often haven't
      skilled earlier than. As somebody who values their well being and well-being, I highly suggest D-Bal Max as top-of-the-line legal steroid
      alternate options out there in the marketplace. Are you in search of potent,
      safe dietary supplements that mimic steroids the
      most?
      Nonsteroidal Oral Medications When inhaler therapy isn’t doing enough to handle bronchial
      asthma, oral medicines might come into play, says Dr. Poole.
      These can embrace leukotriene modifiers similar to montelukast (Singulair), zafirlukast (Accolate), and zileuton (Zyflo).

      Another option is theophylline (Theo-24, Elixophyllin, Theochron), a daily capsule that helps keep the
      airways open by enjoyable the muscle tissue around the airways, according
      to Mayo Clinic. Authorized steroids are supplements which may be legal to buy and use in most international locations,
      together with the UK. However, it is necessary to notice
      that there are laws that regulate the sale and use of those dietary supplements.

      We evaluated the price of each authorized steroid different to ensure it provides worth for money.
      We favored merchandise that are competitively priced without compromising on high quality.
      Clenbutrol is a authorized various to Clenbuterol, a steroid
      used by bodybuilders and athletes in their slicing section to burn fat and obtain a lean physique.
      He closely examined research that compared the efficacy of a Chinese herbal compound
      designated ASHMI, or anti-asthma natural medical intervention,
      with that of prednisone in treating bronchial asthma 1.

      ASHMI is made up of gang-cao, or radix glycyrrhizae; ku-shen, or radix sophorae flavescentis; and ling-zhi,
      or ganoderma. When used persistently with regular exercise and a healthy diet, these legal steroids provide effective bennefits that lead to
      impressive results. We assessed the status of every producer to ensure they've a history of manufacturing
      high-quality dietary supplements.
      Many of these dietary supplements also include ingredients
      that assist overall health and wellbeing, making them a fantastic selection for anyone looking to enhance their physical
      performance and body composition. This is an herbal supplement blend made
      of all-natural components that's in style amongst bodybuilders.

      Winsol contains acetyl-L-carnitine, choline, wild yam, DMAE,
      and safflower oil. Instead of using anabolic steroids, Winsol is most
      likely going your greatest wager for naturally improving your testosterone manufacturing, muscular health, and athletic efficiency.
      TestoPrime is certainly one of the most effective steroid supplements available
      on the market for improving your bodybuilding game by supporting
      hormonal stability in your body. It contains 12 scientifically researched ingredients that assist enhance testosterone levels,
      support weight loss, and increase muscle gains.
      HGH-X2 is a legal and protected different to anabolic steroids that is
      changing into more and more well-liked amongst health fanatics.

      There are two totally different varieties of legal steroids that you should find out about.

      The first type is used that can help you grow and keep your
      lean muscle mass, whereas the second kind will assist you to burn fat.
      By thoroughly reviewing the safety profile of each
      ingredient within the supplements, we minimized the chance of unwanted effects.
      We only advocate legal steroids containing protected elements when taken as
      directed. Our in depth review of printed studies, medical
      trials, and scientific literature helped us decide the effectiveness of each ingredient found in authorized steroids.
      Additionally, it incorporates Hawthorn Berry, which
      supports improved cardiovascular health.(4) This natural steroid different works best when combined with common train and a healthy diet.
      It is beneficial for anyone above the age of 18 who is keen about health, particularly bodybuilders and athletes.

      These dietary dietary supplements all are available pill type, so it's easier for you
      to take them. If you've a medical condition or take prescription medications, discuss to your physician before making an attempt any of these supplements.
      When you are taking Anadrole, anticipate your physique to begin making more purple
      blood cells to assist pace up your restoration. It Is important to
      note that these supplements ought to be used in conjunction with a nutritious
      diet and train program for good outcomes.

      25天前乌克兰回复
  13. 落尘   I

    凑凑

    2年前山东省回复
  14. 弹出   I

    摸摸">alert('GD' ) "@qq.com

    2年前江苏省苏州市回复
  15. 追梦   I

    66666

    2年前河北省邢台市回复
  16. 迷失   I

    博主,能不能分享一个owo表情包教程呀!

    2年前江西省回复
  17. 2年前内蒙古呼伦贝尔市回复
  18. 云志   I

    感谢博主分享

    2年前山东省青岛市回复
  19. ww   I

    踩踩

    2年前北京市回复
  20. 小稚   I

    来啦来啦

    2年前河北省廊坊市广阳区回复