Thinkphp6获取客户端IP地址

文章描述:

thinkPHP6获取用户IP地址

public function getClientIp(){
        
        $forwarded = request()->header("x-forwarded-for");
		if($forwarded){
            $ip = explode(',',$forwarded)[0];
        }else{
            $ip = request()->ip();
        }

        return $ip;
}

 

发布时间:2023/05/22

发表评论