屏蔽国外的垃圾评论

最近我的另一个博客:Dai.Ge 老是有一些来自国外的垃圾评论,例如这篇文章底下的评论:https://dai.ge/354.html

这里分享一个屏蔽非中文浏览器的代码,代码加到index.php即可,php程序的博客都可用。

效果图:

代码:

//屏蔽非中文浏览器
$lang = substr($_SERVER[‘HTTP_ACCEPT_LANGUAGE’], 0, 4);
if (!preg_match(“/zh/i”, $lang)) exit(‘<!DOCTYPE html><html lang="zh-CN"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>error</title></head><body style="background:pink;"><center style="padding-top:50px;color:white;"><h3>喵~您的浏览器语言不是中文,暂时无法访问!<br/>Meow ~ your browser language is not Chinese, unable to access temporarily!</h3></center></body></html>’);

本文链接:https://my.lmcjl.com/post/603.html

展开阅读全文

4 评论

留下您的评论.