Jump to content

Filter to omit based on certain url


mherzber

Recommended Posts

I have a script that will send an error for 404 emails. I want to exclude urls from a certain directory. How can I make it so they wont submit if /example is in the url? The code works fine I just want to filter out. Also you will see that I have defined REQUEST_URI this is because I have php on IIS, not my choice. I am somewhat of a noob, so if you can make your answer as simple as possible I would really appreciate it. Here is code:

 

<?
# 404.php - Last updated 3/1/2002, initially released 8/10/2000
# Trap 404 errors and mail a notice to the webmaster
# Now requires PHP4
# Copyright 2000-2002 shaun@shat.net under the GPL v2+

# Set these variables to configure the script:
if (!isset($_SERVER['REQUEST_URI']))
{
    if (!isset($_SERVER['QUERY_STRING']))
    {
        $_SERVER['REQUEST_URI'] = $_SERVER["SCRIPT_NAME"];
    }
    else
    {
        $_SERVER['REQUEST_URI'] = $_SERVER["SCRIPT_NAME"] .'?'.
        $_SERVER['QUERY_STRING'];
    }
}


# Set $domain to your domain name (no www)
$domain = "example.com";

# Set $docroot to the URL of the directory which contains your
# .htaccess file. Don't include trailing slash.
$docroot = "http://www.example.com";

# Font face you'd like to use on the 404 page
$fontface = "Verdana";

# Font size you'd like to use on the 404 page
$fontsize = "2";

# Background color of the 404 page (default is white)
$bgcolor = "#ffffff";

# Text color you'd like to use on the 404 page (default is black)
$textcolor = "#000000";

# This script is capable of mailing the details of each 404 error
# to the webmaster. Use the $reportlevel variable to control when
# you receive these reports.
#
# 0 = don't use the email capabilities
# 1 = send email only if the error's referer contains your domain name
#     (i.e. the 404 was generated by a broken link on your site)
# 2 = send email any time a 404 error is generated (useful for tracking
#     broken links at other sites which link to you)

$reportlevel = 1;

# Set $emailaddress to the email address of whoever should be
# notified of 404 errors. Don't escape the @ symbol.
# You can leave this unassigned if you're not using email features.

$emailaddress = "me@example.com";

#
#Configuration ends here!
#

#Until I rewrite my scripts, this will suffice for bg-compatibility;
if(phpversion() >= "4.2.0"){
   extract($_POST);
   extract($_SERVER);
   extract($_ENV);
}


# The send_email function sends the details of the 404 error to the
# webmaster. 

function send_email(){
   # Request access to the global variables we need
   global $REQUEST_URI, $HTTP_REFERER, $emailaddress, $REMOTE_ADDR, $docroot;

   # Build the $errortime variable to contain the date/time of the error.
   $errortime = (date("d M Y h:m:s")); 

   # Create the body of the email message
   $message .= "404 Error Report\n\nA 404 error was encountered by $REMOTE_ADDR";
   $message .= " on $errortime.\n\n";
   $message .= "The URI which generated the error is: \n$docroot$REQUEST_URI\n\n";
   $message .= "The referring page was:\n$HTTP_REFERER\n\n";

   # Send the mail message. This assumes mail() will work on your system!
   $headers = "From: $emailaddress\nDate: $errortime -0600\n";
   $subject = "404 Error Report";
   mail($emailaddress, $subject, $message, $headers);
   
   return;
  }

# Done with function declarations. Main function begins here.
header("404 Not Found");


# See whether or not we should send an email report. If so, do it.
if ($reportlevel != 0)
  if ($reportlevel == 1) {
    if (eregi($domain,$HTTP_REFERER))   
      send_email(); }
  else
     send_email();
   
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.