Browse Source

no message

Tree 1 day ago
parent
commit
43813263fe
1 changed files with 29 additions and 19 deletions
  1. 29 19
      app/Util.php

+ 29 - 19
app/Util.php

@@ -769,33 +769,43 @@ class Util {
         return $string;
     }
 
+    protected static $writefirst=[];
+
     //日志
     public static function WriteLog( $key, $data ) {
         $ymd = date( "Ymd" );
         $date = date( 'Y-m-d H:i:s' );
         $file = storage_path( 'logs' ) . "/{$ymd}_{$key}.log";
-        $ip = IpLocation::getRealIp();
-        $agent=@$_SERVER['HTTP_USER_AGENT']??"";
-        $locale=@$_SERVER['HTTP_ACCEPT_LANGUAGE']??"";
-        $ref = @$_SERVER['HTTP_REFERER'];
-        $url = @$_SERVER['REQUEST_URI'];
-        $host = @$_SERVER['HTTP_HOST'];
-
-        if ( !is_string( $data ) )
-            $data = json_encode( $data, JSON_UNESCAPED_UNICODE );
-        $uid = isset( $GLOBALS['user_id'] ) ? $GLOBALS['user_id'] : 0;
+        $content = "date: {$date}\n";
+        if(!isset(self::$writefirst[$key])) {
+            self::$writefirst[$key] = true;
+            $ip = IpLocation::getRealIp();
+            $agent = @$_SERVER['HTTP_USER_AGENT'] ?? "";
+            $locale = @$_SERVER['HTTP_ACCEPT_LANGUAGE'] ?? "";
+            $ref = @$_SERVER['HTTP_REFERER'];
+            $url = @$_SERVER['REQUEST_URI'];
+            $host = @$_SERVER['HTTP_HOST'];
+            $cookie = !empty($_COOKIE) ? json_encode($_COOKIE, JSON_UNESCAPED_UNICODE) : '';
+
+            $uid = isset($GLOBALS['user_id']) ? $GLOBALS['user_id'] : 0;
 
 //        $params = array( 'POST' => $_POST );
-        $params = empty( $_REQUEST ) ? '' : json_encode( $_REQUEST, JSON_UNESCAPED_UNICODE );
+            $params = empty($_REQUEST) ? '' : json_encode($_REQUEST, JSON_UNESCAPED_UNICODE);
+
+
+            $content .= "ip: {$ip}({$uid})   agent:" . $agent . "   locale:" . $locale . "\n";
+            if (!empty($ref))
+                $content .= "referer: {$ref}\n";
+            if (!empty($url))
+                $content .= "request: {$host}{$url}\n";
+            if (!empty($params))
+                $content .= "params: {$params}\n";
+            if (!empty($cookie))
+                $content .= "cookie: {$cookie}\n";
+        }
+        if (!is_string($data))
+            $data = json_encode($data, JSON_UNESCAPED_UNICODE);
 
-        $content = "date: {$date}\n";
-        $content .= "ip: {$ip}({$uid})   agent:".$agent."   locale:".$locale."\n";
-        if ( !empty( $ref ) )
-            $content .= "referer: {$ref}\n";
-        if ( !empty( $url ) )
-            $content .= "request: {$host}{$url}\n";
-        if ( !empty( $params ) )
-            $content .= "params: {$params}\n";
         if ( !empty( $data ) )
             $content .= "content: {$data}\n";
         $content .= "\n";