Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 240
  • Last Modified:

get referring pages for 404 mail to webmaster

is there any way to make a 404 page that can email to a specific address the page the user was trying to reach when he or she got the 404.  The examples I've seen online just print out 404.php when they try to email where the user came from, which is not very useful. I've tried working with javascript referrers (but they seem only to work if a link is pressed, not something mis-typed or given to the user incorrectly), and some php $_SERVER inquires, but i can't seem to get it to work..

Grateful for any ideas!
Thank you.
  • 7
  • 4
1 Solution
Hendrik WieseInformation Security ManagerCommented:

Please refer to the following link to setup a 404 page that emails:
hibbsusanAuthor Commented:
for me, this just shows the 404.php file as the url that access was attempted on.  can't i get the site that the user typed in?

hibbsusanAuthor Commented:
my last post was worded poorly.

In the email I receive from this script, I would like to see what url the user tried to load.

for example: user wants to see the page with images, so he types:

and he gets a 404 because the url that has images is actually located at:

in the email I receive i would like to see:
"User got a 404 when he tried to go here:"

But with this program, I see:
"User got a 404 when he tried to go here:"

well, or course that's not what he tried to access. That's just the last page he was on, and pretty useless :(

Is there anyway to see exactly when he typed in the browser before being re-directed to the 404?

Get 10% Off Your First Squarespace Website

Ready to showcase your work, publish content or promote your business online? With Squarespace’s award-winning templates and 24/7 customer service, getting started is simple. Head to and use offer code ‘EXPERTS’ to get 10% off your first purchase.

Hendrik WieseInformation Security ManagerCommented:

With regards to the link I posted, you will get a notification that the user was trying to access and not the 404.php url. It will however not be able to tell you that the actual location is as you cannot determine this.

So in short:
1. You will receive an email showing you the page that the user was trying to load for example:
2. You cannot determine what it should have been using code: The only way to do this would be to Analyse the result that the script sends you and then create an additional directory called img and add a page with the same name that directs the user to the correct location.
3. Same as point 1
4. This example that I posted will not send you the as it captures the url that the user was trying to access from the start.

Hope this helps!!!
hibbsusanAuthor Commented:
First of all, I definitely don't expect this to redirect the user to the appropriate page, or anything like that. I just want to get an email with the incorrectly typed address.

I wish I could get this software to work like this. I've set it up and it really does simply send me the 404.php url. There are several similar comments on the site. I imagine it's a simple matter of overlooking something obvious, because the author has set it up so you only have to plug in about three variables.

Have you got a working sample of the code I could look at? Or could you forward one of the emails so I could see it in action?

Thanks for your help!
Hendrik WieseInformation Security ManagerCommented:
I have tested it on my domain and the output was the following:

There was a 404 Not Found error on the domain

When: Mon Sep 19 2011 12:13:36 pm SAST
(Who) IP Address:
(What) Tried to Access:
(From where) HTTP Referer:

User Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +
hibbsusanAuthor Commented:
For me it looks like this:

 404 email notification
hibbsusanAuthor Commented:
do you have any ideas? can I see a copy of your code and .htaccess?

I can't figure out what the problem could be ><

Hendrik WieseInformation Security ManagerCommented:
My .htaccess has got the following 2 entries in as suggested by the site:

ErrorDocument 404 /error/404.php  
ErrorDocument 403 /error/403.php



header("HTTP/1.0 404 Not Found");	// Send correct HTTP Header
$error_code = '404 Not Found';		// Specify the error code
require_once('');	// Include the error mailer script


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "">
<html xmlns="" xml:lang="en">

<title>404 Not Found - The page or file you requested does not exist.</title>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta http-equiv="Content-Style-Type" content="text/css" />
	<link href="" rel="stylesheet" type="text/css" />

	<div id="wrapper">
		<img src="" alt="404 Error Oops!" title="404 Error Oops!" />
		<h1 class="loud">Sorry! We couldn't find it.</h1>
		<p class="loud">You have requested a page or file which does not exist so we 
		notified the web administrator to check it out.</p>
		<p class="small">Here are a few options to find what you are looking for.</p>
			<li><span>Double check the web address for typos</span></li>
			<li><span>Head back to our home page via the navigation below</span></li>
			<li><span>Contact us by <a href="">clicking here</a></span></li>
			<li><a href="">Home</a></li>
			<li><a href="">Blog</a></li>
			<li><a href="">Free Fax to Email</a></li>
			<li class="last"><a href="">Contact</a></li>
	</div><!-- end div #wrapper -->

Open in new window

hibbsusanAuthor Commented:
Can you attach your directory?

i'm confused about this folder 'error'. it is not in the downloadable files on the site, but he references them (as do you) in your .htaccess and in the 404.php file.

hibbsusanAuthor Commented:
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now