Go Premium for a chance to win a PS4. Enter to Win


get referring pages for 404 mail to webmaster

Posted on 2011-09-19
Medium Priority
Last Modified: 2012-05-12
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.
Question by:hibbsusan
  • 7
  • 4
LVL 21

Accepted Solution

Hendrik Wiese earned 2000 total points
ID: 36559127

Please refer to the following link to setup a 404 page that emails: http://net.tutsplus.com/tutorials/php/404403-website-error-pages-with-php-auto-mailer/

Author Comment

ID: 36569730
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?


Author Comment

ID: 36569822
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?

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36572876

With regards to the link I posted, you will get a notification that the user was trying to access http://www.mysite.com/images and not the 404.php url. It will however not be able to tell you that the actual location is http://www.mysite.com/img 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: www.yoursite.com/images
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 www.mysite.com/404.php as it captures the url that the user was trying to access from the start.

Hope this helps!!!

Author Comment

ID: 36573299
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!
LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36573644
I have tested it on my domain and the output was the following:

There was a 404 Not Found error on the www.helewix.com domain

When: Mon Sep 19 2011 12:13:36 pm SAST
(Who) IP Address:
(What) Tried to Access: http://www.helewix.com/main/index.php?page=shop.ask&flypage=flypage.tpl&product_id=251&category_id=63&option=com_virtuemart&Itemid=59
(From where) HTTP Referer:

User Agent: Mozilla/5.0 (compatible; Googlebot/2.1; +http://www.google.com/bot.html)

Author Comment

ID: 36573674
For me it looks like this:

 404 email notification

Author Comment

ID: 36577017
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 ><

LVL 21

Expert Comment

by:Hendrik Wiese
ID: 36578947
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('http://www.helewix.com/error/error-mailer.php');	// Include the error mailer script


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" 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="http://www.helewix.com/error/styles.css" rel="stylesheet" type="text/css" />

	<div id="wrapper">
		<img src="http://www.helewix.com/error/oops.jpg" 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="http://helewix.com/contact-us.php">clicking here</a></span></li>
			<li><a href="http://www.helewix.com">Home</a></li>
			<li><a href="http://www.helewix.com/blog/">Blog</a></li>
			<li><a href="http://helewix.com/free-fax-to-email.php">Free Fax to Email</a></li>
			<li class="last"><a href="http://helewix.com/contact-us.php">Contact</a></li>
	</div><!-- end div #wrapper -->

Open in new window


Author Comment

ID: 36582546
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.


Author Closing Comment

ID: 36894024

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . It goes without saying that technology has transformed society and the very nature of how we live, work, and communicate in ways that would’ve been incomprehensible 5 ye…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question