xiang 6 年 前
コミット
51262bc188

+ 17 - 2
vendor/GatewayWorker_linux/GatewayWorker/Applications/whisper/start_gateway.php

@@ -87,10 +87,16 @@ $gateway->onConnect = function ($connection) {
             $connection->close();
             return;
         }
-        $_SESSION['remotip'] = isset($_SERVER['HTTP_X_REAL_IP']) ? $_SERVER['HTTP_X_REAL_IP'] : $connection->getRemoteIp();
+
+        $_SESSION['remotip'] = isset($_SERVER['HTTP_X_REAL_IP'])  ? $_SERVER['HTTP_X_REAL_IP'] : $connection->getRemoteIp();
+        //从cdn中提取ip
+        $ips = getRealIp($_SERVER['HTTP_X_FORWARDED_FOR']);
+        if (!empty($ips)) {
+            $_SESSION['remotip'] = $ips;
+        }
         $_SESSION['remotport'] = $connection->getRemotePort();
         $_SERVER['REMOTE_ADDR'] = $_SESSION['remotip'];
-        print_r(['rip' => $_SESSION['remotip'], 'sip' => $_SERVER]);
+
 
 
         // 可以在这里判断连接来源是否合法,不合法就关掉连接
@@ -104,7 +110,16 @@ $gateway->onConnect = function ($connection) {
     };
 };
 
+
+
 // 如果不是在根目录启动,则运行runAll方法
 if (!defined('GLOBAL_START')) {
     Worker::runAll();
 }
+
+
+function getRealIp($addr)
+{
+    $ips = explode(',', $addr);
+    return isset($ips[0]) ? $ips[0] : '';
+}