Jamit Software Forum
Welcome, Guest. Please login or register.
July 16, 2019, 08:40:43 am

Login with username, password and session length
Search:     Advanced search
May 27th, 2009 - Jamit Software Launches the forum today!
3,080 Posts in 791 Topics by 1,542,158 Members
Latest Member: FloydCape
* Home Help Search Login Register
+  Jamit Software Forum
|-+  Jamit Job Board Customers
| |-+  User-to-User Support
| | |-+  404 error trick
« previous next »
Pages: [1] Print
Author Topic: 404 error trick  (Read 2983 times)
zorab
Guest
« on: January 06, 2011, 11:03:15 pm »

Hello,

Been searching for 404 errors and how to redirect them and i found a good trick for and very usefull so i think its a good idea to share with JJB you never know who's gonna need it.
It redirects the user to the page he used to be before and its sending you an email with a description of error which user encounter.
Just create an .txt file named 404.txt ....copy and paste the below text into....save...rename the 404.txt to 404.php ....upload it to your public folder for your website and should work. It worked well for me and is doing a very good job.
P.S. you need to add ErrorDocument 404 /404.php in your .htaccess file in order to work.
I've added the file as attachment if you're lazy enough. Grin Edit it as you like.
I hope I've been friendly enough with the description. 
ENJOY

<?php
$sendMail = "yes";   // must be set to "yes" for the email to be sent
$emailAddress = "[email protected]";  // set to your email address
putenv('-2GMT');  // set to your time zone
// change nothing below this line
$domain = $_SERVER['HTTP_HOST'];
$page = $_SERVER['REQUEST_URI'];
if ($sendMail == "yes") {
  $errortime = (date(" F d h:ia"));
  $browser = $_SERVER['HTTP_USER_AGENT'];
  $referer = $_SERVER['HTTP_REFERER'];
  $IP = $_SERVER['REMOTE_ADDR'];
  $message = "";
  $message .= "Time of the error: $errortime\n\n";
  $message .= "browser: $browser\n\n";
  $message .= "Page Requested: $domain$page\n\n";
  $message .= "Referer: $referer\n\n";
  $message .= "IP Address: $IP\n\n";
  $name = gethostbyaddr($IP);
  $message .= "Hostname: $name\n\n";
  mail($emailAddress, "404 Error" , $message, "From: Website <>");
}
header("HTTP/1.0 404 Not Found");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<meta http-equiv="refresh" content="1;url=http://www.yoursite.com/">
<title>404 - where oh where?</title>
<style type="text/css">
A:link {text-decoration: none; font-weight:bold; color: blue}
A:hover {color: red}
</style>
</head>
<body>
<div style="width: 400px; position: absolute; top: 45px; left: 50%; margin-left: -200px;">
<span style="color: teal; font-size: 32px;">file not found</span>
<br /><br /><br />
<span style="color: black; font-size: 18px;">
(oops)
<br /><br />
it appears you were looking for
<br />
<span style="color: teal; font-size: 18px;"><?=$domain?><?=$page?></span>   
<br /><br /> 
however, since you are here, it is clear you did not get what you wanted.
<br /><br /> 
the problem has been reported so any broken links can be found and repaired.
<br /><br /> 
you can click <a href="javascript:history.go(-1)">here</a> to go back to your previous page.
</span>
</div>
</body>
</html>
Logged
steve
Jammers
Hero Member
*
Posts: 150


« Reply #1 on: January 07, 2011, 04:11:57 am »

That looks pretty cool. I've been using "ErrorDocument 404 http://www.mycoolsite.com" to redirect back to the home page.

I will try this out and see what it looks like.
Logged
steve
Jammers
Hero Member
*
Posts: 150


« Reply #2 on: January 07, 2011, 04:13:41 am »

I would also add an option to go to the home page in addition to the link to go back to the previous page.
Logged
Imran
Global Moderator
Hero Member
*****
Posts: 255


WWW
« Reply #3 on: January 08, 2011, 07:20:32 am »

Thanks, I have been using similar script on one my sub pages.
It works out really nice, and sends out an email about 404 so that we can fix it and displays a nice message.
Logged
jaffri
Jammers
Sr. Member
*
Posts: 51


« Reply #4 on: January 08, 2011, 08:27:51 am »

In the attached file, dont we need to replace "http://www.yoursite.com/" in line 28 with the JJB site's own domain?
Logged
zorab
Guest
« Reply #5 on: January 08, 2011, 09:58:00 am »

Yes jaffri correct
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.14 seconds with 17 queries.