I had a strange problem after moving to a new server. Cron to receive mail checks for authorized IP addresses, one of which by default is 127.0.0.1
It stops working after moving because the REMOTE_ADDR variable is not populated. It is called from the browser, but not when running from within cron or from the console with php. I reset the $ _SERVER variable and that’s all it has from cron / console
(
[SHELL] => /bin/sh
[MAILTO] => *removed*
[USER] => *removed*
[PATH] => /usr/bin:/bin
[PWD] => /homepublic_html/support/cron.php
[SCRIPT_NAME] => /homepublic_html/support/cron.php
[SCRIPT_FILENAME] => /homepublic_html/support/cron.php
[PATH_TRANSLATED] => /homepublic_html/support/cron.php
[DOCUMENT_ROOT] =>
[REQUEST_TIME] => 1300522141
[argv] => Array
(
[0] => /homepublic_html/support/cron.php
)
[argc] => 1
)
if(!$cron->isValidIp($_SERVER['REMOTE_ADDR'])) {
echo sprintf("[ERROR]: Your IP %s is not authorized to run scheduled tasks. Please notify your administrator.",
$_SERVER['REMOTE_ADDR']
);
if(is_array($this->valid_ips))
foreach($this->valid_ips as $mask) {
if(empty($mask)) continue;
if(0 == strcmp(substr($ip,0,strlen($mask)),$mask)) {
return true;
}
source
share