As explained in this recurring thread:
PHP and cron: security issues
You must store this file outside of public_html.
Sometimes, however, this is not possible. My mind went to Moodle , where a similar function exists. This is what they do.
From cron.php:
...
if (!isset($_SERVER['REMOTE_ADDR']) && isset($_SERVER['argv'][0])) {
chdir(dirname($_SERVER['argv'][0]));
}
...
if (isset($_SERVER['REMOTE_ADDR'])) {
if (!empty($CFG->cronclionly)) {
print_error('cronerrorclionly', 'admin');
exit;
}
if (!empty($CFG->cronremotepassword)) {
$pass = optional_param('password', '', PARAM_RAW);
if($pass != $CFG->cronremotepassword) {
print_error('cronerrorpassword', 'admin');
exit;
}
}
}
...
source
share