Referencing REMOTE_ADDR directly messes command line wp-cron.php
-
Running wp-cron.php through shell with
php -f /PATH/TO/WP/wp-cron.php
as instructed for example in https://buildyourblog.net/problems/disable-wp-cron-running-background resulted in a number of error messages starting with these by Dynamic Widgets:PHP Notice: Undefined index: REMOTE_ADDR in /PATH/TO/WP/wp-content/plugins/dynamic-widgets/classes/dynwid_class.php on line 615 Notice: Undefined index: REMOTE_ADDR in /PATH/TO/WP/wp-content/plugins/dynamic-widgets/classes/dynwid_class.php on line 615
The rest of the messages were similarly caused by Dynamic Widgets having sent the headers already. It’s likely related to the server having PHP notices enabled and a reference to undefined REMOTE_ADDR thus causing the output to start.
Also, the check with strstr() when returning the IP currently limits the support to only IPv4 addresses. The whole check seems a bit odd but perhaps there’s a reason for it I haven’t thought of. In any case it’s easy to expand it to support IPv6 as well.
Both fixes can be applied by changing in classes/dynwid_class.php lines 615-618 from
$ip = $_SERVER['REMOTE_ADDR']; $this->message( 'Raw IP: ' . $ip ); return ( strstr($ip, '.') !== FALSE ) ? $ip : NULL;
to
if ( ! empty( $_SERVER['REMOTE_ADDR'] ) ) { $ip = $_SERVER['REMOTE_ADDR']; } else { $ip = NULL; } $this->message( 'Raw IP: ' . $ip ); return ( strstr($ip, '.') !== FALSE || strstr($ip, ':') !== FALSE ) ? $ip : NULL;
- The topic ‘Referencing REMOTE_ADDR directly messes command line wp-cron.php’ is closed to new replies.