If I were you I would make extended condition for CLI request or let's say admin approach.
CI3
<?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
}
}
CI2
<?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
}
}
To explain this: CLI checking ( check CodeIgniter Input class/library ) will allow server to approach through cronjob, and checking if admin will allow authorized user to make call over that controller as well. So you don't bother with IP because authorized person can make cron job even from other locations.
In other words, anyone that is not SERVER
or admin couldn't call this controller/method
.