Restrict Access Based on IP Address |
I'm developing a timeclock application that needs to restrict access based on the visitor's IP Address. This code worked on my testing server but not on any of my production hosts: <cfset Session.IPAdd="#CGI.Remote_Addr#"> <cfquery name="IPs" datasource="101TC"> SELECT Table_IpAllowed.autonum, Table_IpAllowed.IPAllowed FROM Table_IpAllowed WHERE (((Table_IpAllowed.IpAllowed)="<cfoutput>#Session.IPAdd#</cfoutput>")); </cfquery> <cfif IPs.RecordCount EQ "0"> <cflocation url = "iprejected.cfm"> </cfif> Based on a couple of forums I visited, this is probably a bug in Access 2007. I finally found some code here that was almost usable. With a few added parentheses the working code became this: <cfif #cgi.remote_addr# NEQ "12.345.678.9" AND #cgi.remote_addr# NEQ "127.0.0.1"> <!--- Redirect To An Error Invalid Page Access ---> <cflocation url='iprejected.cfm' addtoken='No'> <cfexit method='EXITTEMPLATE'> </cfif> |
Archives