Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PHP Error Pages

7 views
Skip to first unread message

Sean Rachal

unread,
Jul 25, 2012, 12:54:07 PM7/25/12
to
Hello all,

I have an interesting issue.

I have a single error page that catches several different site errors. I also have that page give the user the option to submit a report to the webmaster (me). The only thing that the user sees, is the details. As soon as I have it fully operational, I will be only serving up an error description and automatically send the email.

Here is the issue:

So far I am catching any database, 404 and 403 errors. I show the errors and then have a form with a submit button and several hidden inputs. some of the inputs depend on the type of error. If it was some database error, then the form populates with those errors. My .htaccess file directs to the same error page with a code that I then set to a variable and another to the address location of the missing file. I then return the user to the home page.

- When I get the database errors, the page displays properly and the submit button works works. I get the email and the page returns to the home page.

- When I get the 404/404 errors, the page displays properly, but the submit button doesn't do anything.

This is driving me crazy. I have tried it using the same file, and separate files (error, 404 and 403), neither method works. I still don't get the email or redirect.

After that long-winded explanation, here is some code:

.htaccess:
- ErrorDocument 403 /error.php?error=403
- ErrorDocument 404 /error.php?error=404

error.php:

email portion:

$uri = $_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
if(!empty($_GET['error'])) {
$error = $_GET['error'];
}

include 'include/includes.php';

// error report to ...
define("EMAIL", "Errors <m...@myDomain.com>");
if(isset($_POST['submit'])) {
//assign post data to variables
$name = trim($_POST['input_0']);
$email = trim($_POST['input_1']);
$message = trim($_POST['input_2']);
$message1 = trim($_POST['input_3']);

$header = 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= "From: $name <$email>\n" . "Reply-To: $name <$email>\n";
$subject .= "Errors Detected on Website";
$email_to .= EMAIL;
$emailMessage .= "The following errors were detected on your website:<br /><br />";
$emailMessage .= $message.'<ul>';
$emailMessage .= $message1.'</ul>';

//use php's mail function to send the email
@mail($email_to, $subject ,$emailMessage ,$header );

//set the url, and then redirect to that url
$url = "http". ((!empty($_SERVER['HTTPS'])) ? "s" : "") . "://".$_SERVER['SERVER_NAME'].'/';
header('Location: '.$url);
}// end isset; send error report

display and form:

<?php
if(!empty($error)) {
if($error === '404' || $error === '403') {
echo "<h1 style=\"color:#fff; text-align:center;\">404 Not Found</h1>";
echo '<p>The file '.$uri . ' was not found on this server.</p><br />';
}// end 404/403
// end page error
} elseif(!empty($err)) {
echo $err['message'];
echo $err['errors'];
}// end database errors
?>
<p>Please click the submit button to report these errors.</p>
<form method="post" action="" name="frm">
<input type="hidden" name="input_0" value="name for email header" />
<input type="hidden" name="input_1" value="m...@myDomain.com" />
<?php if(!empty($err)) :?>
<input type="hidden" name="input_2" value="<?php echo $err['submitText']; ?>" />
<input type="hidden" name="input_3" value="<?php echo $err['submitErrors']; ?>" />
<?php elseif(!empty($error)) :?>
<input type="text" name="input_2" value="Error: <?php if($error === '404' || $error === '403') { echo $error.' Not Found'; };?>" />
<input type="text" name="input_3" value="<?php echo $uri;?> was not found on this server." />
<?php endif;?>
<div class="submit" style="text-align:center;">
<input class="submitbutton" type="submit" name="submit" value="Submit" />
</div>
</form>

I hope this helps understand my issue. Any help would be appreciated.
0 new messages