Skip to content

Instantly share code, notes, and snippets.

@pud
Last active December 26, 2015 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pud/7075368 to your computer and use it in GitHub Desktop.
Save pud/7075368 to your computer and use it in GitHub Desktop.
Get user's real IP address behind an Amazon AWS load balancer.
<cfif structkeyexists(GetHttpRequestData().headers,"X-Forwarded-For")>
<!--- ipaddress if user is behind load balancer --->
<cfset my_ip = #GetHttpRequestData().headers['X-Forwarded-For']#>
<cfset my_ip = trim(listgetat(my_ip,1))>
<cfelse>
<!--- ipaddress if user is not behind load balancer --->
<cfset my_ip = cgi.remote_addr>
</cfif>
<cfoutput>
Your IP address is: #my_ip#
</cfoutput>
@bluesmoon
Copy link

You can't trust the value of X-Forwarded-For since a user can fake it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment