Multiple OR for Badwords

Hi guys,

I’m currently using this code to check for badwords in name and comments inputs:

foreach ($badwords as $word)
if (
strpos(strtolower($_POST[‘name’]), $word) !== false ||
strpos(strtolower($_POST[‘comments’]), $word) !== false
)

{
	echo 'critical error';
	exit(); 
}

However, I need to check a 3rd input, ‘company’. In doing this:

       strpos(strtolower($_POST['name']), $word) !== false ||
       strpos(strtolower($_POST['comments']), $word) !== false ||
       strpos(strtolower($_POST['company']), $word) !== false

The new, third option seemingly gets bypassed. Is it not possible to use multiple or operators in this way?

Any suggestions on how to approach this, please?

You should certainly be able to have multiple ORs.

The only reason it would “skip” checking is if one of the earlier conditions was true.

if (this || that || other) { }

If “this” is true, then it doesn’t have to check “that” or “other” at all.
If “that” is true, then it doesn’t have to check “other” at all.
If “other” is true, it should work fine. Multiple ORs are ok.

It would be critically important here to make sure your inputs are sane. For example is it possible that a $word could be an empty string? Or not a string at all?
And make triple sure there isn’t a typo/syntax error somewhere.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.