thinkphp屏蔽ip访问项目做法

1.从入口文件下手,首先在index.php中顶部加入:(这一步是为了让显示信息以utf8编码格式显示)

header("Content-Type:text/html;charset=utf8"); 

2.找到thinkphp文件夹下start.php文件:

<?php
namespace think;
use think\Request;
require __DIR__ . '/base.php';
$request = Request::instance();
$request->ip();
if($request->ip()=='124.116.71.69'){
    echo '您无权访问此网站!';
	exit;
}
// 2. 执行应用
App::run()->send();

这个功能可以添加再后台设置多个ip被屏蔽访问,这里的需求只屏蔽一个,其它可自行扩展

路是自己走出来的,而不是选出来的。
原文地址:https://www.cnblogs.com/mo3408/p/15741748.html