Last active
December 26, 2015 01:59
-
-
Save pud/7075368 to your computer and use it in GitHub Desktop.
Get user's real IP address behind an Amazon AWS load balancer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can't trust the value of X-Forwarded-For since a user can fake it.