Welcome Guest, Not a member yet? Register   Sign In
advanced 404 error handling
#1

[eluser]exodus7[/eluser]
Hey guys,

I was wondering if there was an easy way to email all 404 errors when they occur, but check if certain URI characters are present before sending out the email...

Here's my dilemma- I set up this simple function to send me mail (on the 404 error page)

Code:
if(stristr($_SERVER['PHP_SELF'],'undefined') === FALSE)
{
    $to        =  "[email protected]";
    $subject   =  "404 ERROR OCCURRED";
    $emessage   =  "404 ERROR Occurred on your website. \n The URL is:".$_SERVER["PHP_SELF"]."\nOther Info:".$_SERVER['HTTP_REFERER']."\n".$_SERVER['REQUEST_URI'];

    //mail  headers
    $headers   =  "MIME-Version:  1.0\n";
    $headers  .=  "Content-type:  text/plain;  charset=iso-8859-1\n";
    $headers  .=  "X-Priority:  3\n";
    $headers  .=  "X-MSMail-Priority:  Normal\n";
    $headers  .=  "X-Mailer:  php\n";
    $headers  .=  "From:  \"noreply\"  <[email protected]>\n";
    $headers  .=  "Return-Path:  [email protected]\n";
    $headers  .=  "Return-Receipt-To:  [email protected]\n";

    mail($to,$subject,$emessage,$headers);

}

But due to my lack of php/programming knowledge, I simply don't know how I need to modify it to check if certain words like "wpad.dat" or "SimpleAuthWebService/SimpleAuth.asmx" are in the URI, NOT to email me.

The script above seems to send me EVERY 404 occurrence even if I add an 'if-or' to include the others I want omitted....

Can someone point me in the right direction?

Thanks :-)
#2

[eluser]Mirage[/eluser]
You should probably look into the preg_match() php function.
#3

[eluser]exodus7[/eluser]
CI Mirage:

Thanks for your. I was able to get it to work using the preg_match() function in an if statement.

Thanks!




Theme © iAndrew 2016 - Forum software by © MyBB