Getting a users IP address using ColdFusion

Readability

Getting a users IP address using ColdFusion

The fol­low­ing exam­ple shows how you can get the IP address of the remote host mak­ing the request by using the CGI.REMOTE_ADDR CGI server variable.

#CGI.REMOTE_ADDR#

And the out­put of the pre­vi­ous snip­pet is as fol­lows:

If you want to deter­mine whether the spec­i­fied IP address is the local­host, you can use the isLocalHost() func­tion, as seen in the fol­low­ing example:

#isLocalHost(CGI.REMOTE_ADDR)#

You can also get the local­host IP address using the getLocalHostIP() func­tion, as seen in the fol­low­ing example:

#getLocalHostIP()#

The following example shows how you can get the IP address of the remote host making the request by using the CGI.REMOTE_ADDR CGI server variable.

<cfoutput>#CGI.REMOTE_ADDR#</cfoutput>

And the output of the previous snippet is as follows:

If you want to determine whether the specified IP address is the localhost, you can use the isLocalHost() function, as seen in the following example:

<cfoutput>#isLocalHost(CGI.REMOTE_ADDR)#</cfoutput>

You can also get the localhost IP address using the getLocalHostIP() function, as seen in the following example:

<cfoutput>#getLocalHostIP()#</cfoutput>

Leave a Reply

Your email address will not be published.