#每日一个小代码#只允许中国用户访问

嗯用免费空间的孩子们经常会想去掉广告啊什么的,或者TOS里面明确写着不允许中文网站自己却偷偷的搭建中文站什么的很苦恼……嗯没关系,有了这个神器,再也不怕老外查站了!

$language = substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],0,2);
//获取访客语言,是HTTP头信息的ACCEPT_LANGUAGE的前两个字符
if($language != 'zh'){
//zh是中文,包括zh-CN简体中文和zh-TW正体中文
header("Location: /yourpage.html");
//这句代码是将用户转向到根目录的yourpage.html这里
exit;
//然后退出
}

简洁的几句话就将非中文用户阻挡在外了。这个yourpage.html里面可以写上:We're sorry but our web site is temporarily unavailable due to routine maintenance or unexpected technical problems. We apologize for the inconvenience and are quickly working to correct the situation. 这一看就很专业的英文报错了对吧……