Files
wh-api/app/Service/SysService.php
ykxiao 0b2299c427
Some checks failed
Build Docker / build (push) Has been cancelled
协程版仓库后端项目
2025-07-08 14:59:47 +08:00

48 lines
1.2 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/**
* Author: ykxiao
* Date: 2025/6/4
* Time: 上午9:51
* Description:
*
* (c) ykxiao <yk_9001@hotmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
declare(strict_types=1);
namespace App\Service;
use Psr\Http\Message\ServerRequestInterface;
/**
* Author: ykxiao
* Date: 2025/6/4
* Time: 上午10:19
* Description: 系统服务
*
* (c) ykxiao <yk_9001@hotmail.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
class SysService
{
/**
* 获取客户端IP信息
* @param ServerRequestInterface $request
* @return string
*/
public function getClientIpInfo(ServerRequestInterface $request): string
{
// 尝试从请求头获取客户端真实IP或转发的IP
$realIP = $request->getHeaderLine('x-real-ip');
$forwardedFor = $request->getHeaderLine('x-forwarded-for');
// 确定客户端IP优先使用 x-real-ip其次是 x-forwarded-for最后是默认IP
$clientIP = $realIP ?: $forwardedFor;
return $clientIP ?: '127.0.0.1';
}
}