Re: Cause of undefined offset notice

From: Date: Sat, 18 Nov 2017 19:41:29 +0000
Subject: Re: Cause of undefined offset notice
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-326268@lists.php.net to get a copy of this message
> On Nov 18, 2017, at 6:08 AM, AshleySheridan <ash@ashleysheridan.co.uk> wrote: > Please never, never use the @ to suppress error messages. Removed. I forgot they were even there. Thanks. > As to your problem, you haven't said what you're feeding into this. The script reads files that contain lists of either full IP addresses or CIDR formatted IP's and will compare the remote IP to see if it's banned. > Have you tried any sort of debugging yet to see why $base > doesn't > have 3 '.' characters? Yes, and I found the problem line. > This probably could be written a bit better. Exploding strings into > parts (where you really only want one substring) is expensive in terms > of CPU cycles, compared to a straight up substring. I was afraid of that. Hopefully I can figure out how to make this better. > Also, have you considered converting the whole IP address into a single > ... > ip2long() will > do this ... It will be far faster than what you're doing, > and make the code a lot simpler and easier to read/manage. This morning I found a blog post about this that seems to handle any situation: https://pgregg.com/blog/2009/04/php-algorithms-determining-if-an-ip-is-within-a-specific-range/ With my limited knowledge on this subject, it seems to me to be a good solution. Thoughts? Thank you, Jenni

« previous php.general (#326268) next »