Show DevBest 404.php (emails you user's data etc...)

Status
Not open for further replies.

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
This took me a while to figure out since i'm mentally retarded but here's some features:
1. Gets the requested URL.
2. Gets their IP.
3. Gets user agent.
4. Emails all of that to you.
Make sure to change the $to variable to your email!
(based on m0nsta.'s email form)
PHP:
<html>
<head>
<title>Error</title>
</head>
<body>
<?php
//let's get some info, shall we?
$ip = $_SERVER['REMOTE_ADDR'];
$error = "404 error";
$to = "[email protected]"; //CHANGE THIS TO YOUR EMAIL
$ua = $_SERVER['HTTP_USER_AGENT'];
$subject = "$error";
$url = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
$message = '
<html>
<body>
<h1>$error</h1><br />
<br />
<strong>IP:</strong> ' . $ip . ' <br />
<strong>Browser agent:</strong> ' . $ua . ' <br />
<strong>Error:</strong> ' . $error . ' <br />
<strong>Requested URL:</strong> ' . $url . ' <br />
</body>
</html>
';
$headers  = 'MIME-Version: 1.0' . "\r\n"; //make sure that HTML is enabled!
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
?>
<?php
//sending that email
mail( $to, $subject, $message, $headers );
?>
<!- Show them the error also! -->
<br />
<h1><?php echo $error; ?> </h1>
<br />
<br />
<p1>Looks like the file or folder you were looking for was not found!<br />
For security reasons we've logged your IP (<?php echo $ip; ?>) was logged. </p1><br />
Info:<br />
<strong>IP:</strong> <?php echo $ip; ?><br />
<strong>Browser agent:</strong><?php echo $ua; ?><br />
<strong>Error:</strong><?php echo $error; ?><br />
<strong>Requested URL:</strong><?php echo $url; ?><br />
<br />
<p1> E-Mail the webmaster here: <?php echo $to ?>
</body>
</html>
Credit to Xenous for showing me how to use custom error pages via .htaccess files
What he gave me:
Code:
<Files .htaccess>
order allow,deny
deny from all
</Files>
ErrorDocument 404 /404.php
Credits:
90% ~ Mace (coding most of it)
5% ~ m0nsta. (the entire $message var)
5% ~ Xenous (.htacces file)
 

leenster

Member
Dec 26, 2011
77
19
I found that a lot of people are having problems sending emails with php. I am logging all 404's and once or twice a week i just go through the logs and fix what needs to be fixed.

PHP:
$loguri=getenv ("REQUEST_URI");
$myFile = "404logs/404log.html";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "<div>".date('l jS \of F Y h:i:s A')." - ".$_SERVER['REMOTE_ADDR']." | URL = ".$loguri."</div>";
fwrite($fh, $stringData);
fclose($fh);

I have that code in the custom 404 page....

I figured i'd post it so people could use it as an alternate solution.
 

Macemore

Circumcised pineapples
Aug 26, 2011
1,681
819
I found that a lot of people are having problems sending emails with php. I am logging all 404's and once or twice a week i just go through the logs and fix what needs to be fixed.

PHP:
$loguri=getenv ("REQUEST_URI");
$myFile = "404logs/404log.html";
$fh = fopen($myFile, 'a') or die("can't open file");
$stringData = "<div>".date('l jS \of F Y h:i:s A')." - ".$_SERVER['REMOTE_ADDR']." | URL = ".$loguri."</div>";
fwrite($fh, $stringData);
fclose($fh);

I have that code in the custom 404 page....

I figured i'd post it so people could use it as an alternate solution.
oh so that logs it to a file! that's a great idea!
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,638
2,393
Nice idea mate. I however won't be using it but it's a neat idea, nice work.
 
Status
Not open for further replies.

Users who are viewing this thread

Top