REMOTE_ADDR empty, not included in SERVER array REMOTE_ADDR empty, not included in SERVER array apache apache

REMOTE_ADDR empty, not included in SERVER array


The $_SERVER['REMOTE_ADDR'] variable is populated because of Apache, running from the command line, this variable won't be set, as well as many others.

Also, even if it were set, REMOTE_ADDR would always be the local ip of the machine the cron is running on, as you wouldn't be able to run it remotely.

[edit]

Just for consistency, here's an example using php_sapi_name

if(php_sapi_name() === 'cli') {    // You're running locally from the CLI} else {    // You're running remotely, check against list of authorized ip addresses.}

In your case, you could just change your if to:

if(php_sapi_name() != 'cli' && !$cron->isValidIp($_SERVER['REMOTE_ADDR'])) {    ....


REMOTE_ADDR isn't populated when run from a command line script, as its value is obtained from HTTP headers.

Are you trying to check this to make sure the script is not run from the web browser? If this is the case you could move it to a directory above the web root and allow cron to run it that way.