From 3b69b81f315eec70f4738ee9f15ec0f426d04fc8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Bar=C3=A1=C5=A1ek?= Date: Sat, 10 Aug 2019 22:02:35 +0200 Subject: [PATCH] InfoPanel: Add information about localhost IP. --- src/Tracy/Bar/panels/info.panel.phtml | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Tracy/Bar/panels/info.panel.phtml b/src/Tracy/Bar/panels/info.panel.phtml index 4eb57c86c..9719299a1 100644 --- a/src/Tracy/Bar/panels/info.panel.phtml +++ b/src/Tracy/Bar/panels/info.panel.phtml @@ -25,6 +25,13 @@ $countClasses = function (array $list): int { })); }; +$ipFormatter = static function (?string $ip): ?string { + if ($ip === '127.0.0.1' || $ip === '::1') { + $ip .= ' (localhost)'; + } + return $ip; +}; + $opcache = function_exists('opcache_get_status') ? @opcache_get_status() : null; // @ can be restricted $cachedFiles = isset($opcache['scripts']) ? array_intersect(array_keys($opcache['scripts']), get_included_files()) : []; @@ -36,8 +43,8 @@ $info = [ 'OPcache' => $opcache ? round(count($cachedFiles) * 100 / count(get_included_files())) . '% cached' : null, 'Classes + interfaces + traits' => $countClasses(get_declared_classes()) . ' + ' . $countClasses(get_declared_interfaces()) . ' + ' . $countClasses(get_declared_traits()), - 'Your IP' => $_SERVER['REMOTE_ADDR'] ?? null, - 'Server IP' => $_SERVER['SERVER_ADDR'] ?? null, + 'Your IP' => $ipFormatter($_SERVER['REMOTE_ADDR'] ?? null), + 'Server IP' => $ipFormatter($_SERVER['SERVER_ADDR'] ?? null), 'HTTP method / response code' => isset($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] . ' / ' . http_response_code() : null, 'PHP' => PHP_VERSION, 'Xdebug' => extension_loaded('xdebug') ? phpversion('xdebug') : null,