From 6e7421214e2ce7e15310cd3d08311ad8310bd86f Mon Sep 17 00:00:00 2001 From: horst Date: Mon, 3 Oct 2016 15:09:50 +0200 Subject: [PATCH] added support for CLI without that, PHP throws notices when try to access the $_SERVER['REMOTE_ADDR'], because it is not set in CLI-Environment. --- wire/core/Session.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/wire/core/Session.php b/wire/core/Session.php index 787311cc..420d65bf 100644 --- a/wire/core/Session.php +++ b/wire/core/Session.php @@ -651,7 +651,11 @@ class Session extends Wire implements \IteratorAggregate { */ public function getIP($int = false, $useClient = false) { - if($useClient) { + if('cli' == php_sapi_name()) { + // when accessing via CLI Interface, $_SERVER['REMOTE_ADDR'] isn't set and trying to get it, throws a php-notice + $ip = '127.0.0.1'; + + } else if($useClient) { if(!empty($_SERVER['HTTP_CLIENT_IP'])) $ip = $_SERVER['HTTP_CLIENT_IP']; else if(!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; else if(!empty($_SERVER['REMOTE_ADDR'])) $ip = $_SERVER['REMOTE_ADDR'];