Forum Moderators: coopster

Message Too Old, No Replies

Checking a string for forbidden substrings

Preventing alerts for common 404 errors

         

Jeremy_H

6:45 pm on Apr 18, 2006 (gmt 0)

10+ Year Member



I'm writing a custom 404 Error page that will also send me an email with the error details.

Now that a version of this page has been setup, I am getting lots of errors for documents like /_vti_bin/owssvr.dll and /MSOffice/cltreq.asp. I know these requests are harmless, and I shouldn't do anything about them.

However, I do want to stop receiving an email notification when these errors occur.

I want to add an if command that will check to see if $_SERVER["REQUEST_URI"] contains /_vti_bin/ or /MSOffice/.

Anybody have any ideas how I might be able to quickly and elegantly check if a string contains any forbidden substrings?

Thanks

Little_G

6:52 pm on Apr 18, 2006 (gmt 0)

10+ Year Member



Hi,

Try:

<?php
$strings = array('/_vti_bin/', '/MSOffice/');
if(strpos($_SERVER["REQUEST_URI"], $strings) === false){
[send email, etc]
}
?>

Andrew

Jeremy_H

6:09 pm on Apr 21, 2006 (gmt 0)

10+ Year Member



Little G, I've tried lots of variations on this, but it seems that it doesn't check the array. Have you, or anyone else, been able to successfully get this to work?

Little_G

7:13 pm on Apr 21, 2006 (gmt 0)

10+ Year Member



Hi,

My mistake, try this:

<?php
$strings = array('/_vti_bin/', '/MSOffice/');
foreach($strings as $temp){
if(strpos($_SERVER["REQUEST_URI"], $temp)!== false){
die("don't send email");
}
}
[send email]
?>

I've swapped the if statement around so that if the forbidden strings are found then the script dies otherwise it sends the email, this is to stop it from sending more than one email.

Andrew