Hello,

with dots in the value of CGI.REMOTE_ADDR, wouldn't this create a bunch of
nested structures ?

application.ipCheck['192']['168']['0']['1'] or
application.ipCheck['192.168.0.1']

Maybe replace the dots with eg an underscore before adding as an element of
the structure?

application.ipCheck['192_168_0_1']

Thanks,
Jean

On Thu, Jan 5, 2012 at 6:20 PM, Matt Woodward <[email protected]> wrote:

> This popped into my head again as I was brushing my teeth this morning
> (which for whatever reason is when I tend to do my best thinking), and
> there's a much more efficient way to do this.
>
> <cfif !StructKeyExists(application, "ipCheck")>
>  <cfset application.ipCheck = {} />
> </cfif>
>
> <cfif StructKeyExists(application.ipCheck, CGI.REMOTE_ADDR)>
>  <cfif DateDiff('s', application.ipCheck[CGI.REMOTE_ADDR], Now()) lte
> 10>
>    BANNED!
>    <cfabort />
>    <cfelse>
>      <cfset application.ipCheck[CGI.REMOTE_ADDR] = Now() />
>      You Pass!
>  </cfif>
>
>  <cfelse>
>    <cfset application.ipCheck[CGI.REMOTE_ADDR] = Now() />
> </cfif>
>
> <cfdump var="#application.ipCheck#" />
>
> Basically that uses structs instead of an array, with the IP address
> as the key of the struct and the timestamp of the last hit as the
> value. That way you don't have to loop over the array to find what
> you're looking for.
>
> --
> online documentation: http://openbd.org/manual/
>   google+ hints/tips: https://plus.google.com/115990347459711259462
>     http://groups.google.com/group/openbd?hl=en
>
>     Join us @ http://www.OpenCFsummit.org/ Dallas, Feb 2012
>

-- 
online documentation: http://openbd.org/manual/
   google+ hints/tips: https://plus.google.com/115990347459711259462
     http://groups.google.com/group/openbd?hl=en

     Join us @ http://www.OpenCFsummit.org/ Dallas, Feb 2012

Reply via email to