允许URL仅在PHP中从允许的IPs计算机命中?
我们已经使用CodeIgnitor PHP框架制作了网站。我们运行一个cron作业来点击一个URL 但有了这个URL,它可以从任何机器上被点击,因为它的功能是用来执行与数据库相关的任务的 我们想使该功能只在服务器IP或特定IP列表中被命中,以便我们只添加允许的机器可以命中该URL允许URL仅在PHP中从允许的IPs计算机命中?,php,codeigniter,Php,Codeigniter,我们已经使用CodeIgnitor PHP框架制作了网站。我们运行一个cron作业来点击一个URL 但有了这个URL,它可以从任何机器上被点击,因为它的功能是用来执行与数据库相关的任务的 我们想使该功能只在服务器IP或特定IP列表中被命中,以便我们只添加允许的机器可以命中该URL 我们如何做到这一点?您可以对apache或nginx使用限制。这样会更安全 对于nginx location /path/to { allow 192.168.1.1/24; allow 127.0.0
我们如何做到这一点?您可以对apache或nginx使用限制。这样会更安全 对于nginx
location /path/to {
allow 192.168.1.1/24;
allow 127.0.0.1;
deny 192.168.1.2;
deny all;
}
对于apache
<Location /path/to>
Order deny,allow
deny from all
allow from 192.168.
allow from 104.113.
</Location >
命令拒绝,允许
全盘否定
允许从192.168开始。
允许从104.113开始。
也许你应该使用.htaccess文件?(如果使用Apache)文档:
如果我是你,我会为CLI请求或管理员方法设置扩展条件。 CI3
我们可以看到crontab中的行吗?它是这样的/usr/bin/GET XYZ.com/FOLDER/index.php/track/addtrack什么是/usr/bin/GET
?它是一个程序吗?我们有apache服务器,在哪里添加它?另外/path/to我们需要在这里定义该url?我们还可以指定准确的IP吗?你能举一个这样的例子吗?我想从2个特定的地址点击这个url,rest all denied:你需要将它添加到你的virtualhost或服务器配置中。路径是一个url匹配,您可以在中找到详细信息。如果您愿意,请参阅我上面的评论,您可以像我所说的那样对示例进行说明,对于此php代码,需要将其放置在该文件中,该函数存在于何处?如果是,那么它是否与Codeignator环境兼容,或者需要附加一些东西?它是纯PHP的,所以是兼容的。如果要使用这段代码,必须将其添加到XYZ.com/FOLDER/index.php
文件的顶部。
<Directory /www>
Order Deny,Allow
Deny from all
Allow from YOUR_IP
</Directory>
$allow = array("123.456.789", "456.789.123", "789.123.456"); //allowed IPs
if(!in_array($_SERVER['REMOTE_ADDR'], $allow) && !in_array($_SERVER["HTTP_X_FORWARDED_FOR"], $allow)) {
header("HTTP/1.0 404 Not Found");
exit();
}
<?php if !defined('BASEPATH') exit('No direct script access allowed!');
class Cronjob extends CI_Controller
{
public function __construct()
{
if (!is_cli() && !is_admin()) {//assuming you have some login/checking module for admin
redirect('welcome', 'refresh')
}
}
public function index()
{
//your code here
}
}
<?php if !defined('BASEPATH') exit('No direct script access allowed!');
class Cronjob extends CI_Controller
{
public function __construct()
{
if (!$this->input->is_cli_request() && !is_admin()) {//assuming you have some login/checking module for admin
redirect('welcome', 'refresh')
}
}
public function index()
{
//your code here
}
}