NameSilo

Custom 404 error page - PHP

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
SpaceshipSpaceship
Watch
Ok, probably not the best thing in the world but I got bored. So yeah, enjoy.

(Btw, this sends email on EVERY 404, soo, if you've got a decent sized site, I'd recommend disabling that..unless you really want a bajillion emails. But oh, why did I write that in .. in the first place? I have no idea..BOREDOM :p )

.htaccess:
Code:
ErrorDocument 404 /404.php

404.php
PHP:
<?php

$config['email'] = '[email protected]';
$config['site_url'] = 'http://www.mysite.com';
$config['subject'] = 'Error: 404 on MySite.com';

function get_ip()
{
  $ip = '';
  if(isset($_SERVER['HTTP_X_FORWARDED_FOR']))
  {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
  }
  else
  {
    $ip = $_SERVER['REMOTE_ADDR'];
  }
  return $ip;
}

$time_stamp = date("l F j Y - g:i:s A");
$ip = get_ip();
$user_agent = $_SERVER['HTTP_USER_AGENT'];
$req_file = $_SERVER['REQUEST_URI'];
$ref_page = $_SERVER['HTTP_REFERER'];

$headers  = 'MIME-Version: 1.0'."\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers .= 'From: '.$config['email'];

@mail($config['email'], $config['subject'], "

<h1>Error - 404</h1>

<b>Date/Time: </b>$time_stamp

<b>User IP: </b>$ip

<b>User's browser: </b>$user_agent

<b>Requested page: </b>$req_file

<b>Referring URL: </b>$ref_page

", $headers);

?>
<html>

<head>
<title>404 Page Not Found</title>
</head>

<body>

<p> </p>
<p> </p>
<p> </p>
<table cellspacing="2" cellpadding="2" style="border: 1 dashed #000000" align="center">
<tr>
  <td bgcolor="#FF0000"><i><h1><font color="#FFFFFF">404 - Page Not Found</font></h1></i></td>
</tr>
<tr>
  <td><p><strong>Sorry, the page you have requested, <?php echo $req_file; ?>, does not exist on this server.</strong></p>
  <p>You have most likely followed a broken link or mis-typed the URL. You can check the URL and try again.<br>
  However, just in case this is an error on our part, an e-mail has been dispatched to the webmaster. <a href="<?php echo $config['site_url']; ?>">Return home</a>.</p>
  <p>Thank you.</p></td>
</tr>
</table>

</body>
</html>
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
I CAN see uses for this for small sites that get a little trafic.. just for link checking...

But MAN! I get like 1200 404s a day from people mistyping imgs I'm hosting! my inbox would be packed! O_O!

Useful though.. to a point.
 
0
Close
AllValley said:
I CAN see uses for this for small sites that get a little trafic.. just for link checking...

But MAN! I get like 1200 404s a day from people mistyping imgs I'm hosting! my inbox would be packed! O_O!

Useful though.. to a point.
Which is why I said
SecondVersion said:
(Btw, this sends email on EVERY 404, soo, if you've got a decent sized site, I'd recommend disabling that..unless you really want a bajillion emails. But oh, why did I write that in .. in the first place? I have no idea..
 
0
Close
got a preview?
 
0
Close
0
Close
how would you disable the email part? I do not know anything about php.
 
0
Close
lasvegascom said:
how would you disable the email part? I do not know anything about php.
PHP:
<?php

$site_url = 'http://www.mysite.com';
$req_file = $_SERVER['REQUEST_URI'];

?>
<html>

<head>
<title>404 Page Not Found</title>
</head>

<body>

<p> </p>
<p> </p>
<p> </p>
<table cellspacing="2" cellpadding="2" style="border: 1 dashed #000000" align="center">
<tr>
  <td bgcolor="#FF0000"><i><h1><font color="#FFFFFF">404 - Page Not Found</font></h1></i></td>
</tr>
<tr>
  <td><p><strong>Sorry, the page you have requested, <?php echo $req_file; ?>, does not exist on this server.</strong></p>
  <p>You have most likely followed a broken link or mis-typed the URL. You can check the URL and try again.<br>
  However, just in case this is an error on our part, an e-mail has been dispatched to the webmaster. <a href="<?php echo $site_url; ?>">Return home</a>.</p>
  <p>Thank you.</p></td>
</tr>
</table>

</body>
</html>
 
0
Close
Or.. you could have it add the data to a database and then have one page to display all of them. Would be just like the email, but easier to read and less annoying.
 
0
Close
thank you
 
0
Close
Appraise.net

We're social

Escrow.com
Spaceship
Domain Recover
CryptoExchange.com

NamePros updates

Switch between accounts
You can now stay logged in to more than one NamePros account in the same browser. Click your avatar, then "Accounts in this browser", to...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back