Skip to content

Instantly share code, notes, and snippets.

Last active December 26, 2015 01:59
What would you like to do?
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))>
<!--- ipaddress if user is not behind load balancer --->
<cfset my_ip = cgi.remote_addr>
Your IP address is: #my_ip#
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