Finding Real IP Address in Coldfusion

I was facing one problem before few days as i was storing ip addresses in my database.
when i looked into database i amazed that there were some entries of ip addresses which were not true.

If anyone is connected to internet through Proxy server then using ‘CGI.REMOTE_ADDR‘ just returns the IP address of proxy server not of the user’s machine.

What we need to do is to compare ‘CGI.HTTP_X_Forwarded_For‘ variable against ‘CGI.REMOTE_ADDR‘.

 

[code:cf]
<cfif CGI.HTTP_X_Forwarded_For EQ ""><!— Checking proxy address —>
<cfset real_ipaddress = CGI.REMOTE_ADDR>
<cfelse>
<cfset real_ipaddress = CGI.HTTP_X_Forwarded_For>
</cfif>

[/code]