1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-13 18:24:57 +02:00

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.
This commit is contained in:
horst
2016-10-03 15:09:50 +02:00
committed by GitHub
parent d698b38d03
commit 6e7421214e

View File

@@ -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'];