Browse Source

Minor: fill REMOTE_ADDR when calling from cli interface

Yannick Warnier 12 years ago
parent
commit
82bb47111f
1 changed files with 4 additions and 1 deletions
  1. 4 1
      main/inc/lib/main_api.lib.php

+ 4 - 1
main/inc/lib/main_api.lib.php

@@ -6157,6 +6157,9 @@ function api_user_is_login($user_id = null) {
 function api_get_real_ip(){
     // Guess the IP if behind a reverse proxy
     global $debug;
+    if (PHP_SAPI === 'cli' && !isset($_SERVER['REMOTE_ADDR'])) {
+        $_SERVER['REMOTE_ADDR'] = 'localhost';
+    }
     $ip = trim($_SERVER['REMOTE_ADDR']);
     if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
         list($ip1,$ip2) = split(',',$_SERVER['HTTP_X_FORWARDED_FOR']);
@@ -6902,4 +6905,4 @@ function api_get_web_default_course_document()
 }
 
 function load_translations($app) {
-}
+}