Re: Better method than stristr

From: Date: Mon, 29 May 2006 19:48:16 +0000
Subject: Re: Better method than stristr
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-237038@lists.php.net to get a copy of this message
Steven Osborn wrote:
        Can someone please advise a faster solution to do what I'm doing  below?  All I need to be able to do is determine if any of the  strings in the array are contained in $q.  The method I have works,  but I'm sure its not the most efficient way to do it.
        $dirtyWord = array("UNION","LOAD_FILE","LOAD DATA INFILE","LOAD  FILE","BENCHMARK","INTO OUTFILE");
        foreach($dirtyWord as $injection)
        {
I don't see a way to avoid the foreach loop, but...
            if(stristr($q,$injection))
rather than stristr() it's faster (MARGINALLY!) to use stripos() and test for a boolean false return value because your not interested in the returned string (so why make php bother with grabbing and returning it)
            {
                //Do Something to remove injection and log it
if you get here I would suggest logging it and then stopping further processing rather than trying to clean up the attempt to perform an sql injection.
            }
        }
       Thank you.
--Steven


« previous php.general (#237038) next »