gpt4 book ai didi

coldfusion - 使用coldfusion获取用户的真实ip地址

转载 作者:行者123 更新时间:2023-12-03 16:42:22 25 4
gpt4 key购买 nike

我发现与用户 IP 相关的唯一变量如下:

<cfif #CGI.HTTP_X_Forwarded_For# EQ "">
<CFSET ipaddress="#CGI.Remote_Addr#">
<cfelse>
<CFSET ipaddress="#CGI.HTTP_X_Forwarded_For#">
</cfif>

还有其他方法可以检查coldfusion中的真实IP地址吗?

最佳答案

您拥有的代码已经在寻找“最知名”的客户端 IP 地址方面做得不错。这是我在项目中使用的过度设计的代码:

public string function getClientIp() {
local.response = "";

try {
try {
local.headers = getHttpRequestData().headers;
if (structKeyExists(local.headers, "X-Forwarded-For") && len(local.headers["X-Forwarded-For"]) > 0) {
local.response = trim(listFirst(local.headers["X-Forwarded-For"]));
}
} catch (any e) {}

if (len(local.response) == 0) {
if (structKeyExists(cgi, "remote_addr") && len(cgi.remote_addr) > 0) {
local.response = cgi.remote_addr;
} else if (structKeyExists(cgi, "remote_host") && len(cgi.remote_host) > 0) {
local.response = cgi.remote_host;
}
}
} catch (any e) {}

return local.response;
}

关于coldfusion - 使用coldfusion获取用户的真实ip地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39017675/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com