/    Sign up×
Community /Pin to ProfileBookmark

creating 404 custom error page help

I wanted to create this custom error page and incorporated with my layout. After I ran it to test, I get couple of line errors. can anyone explain what I need to do? I didn’t edited any lines. It was a copy and paste to a new page.

This is the guide I used.
[url]http://www.webreference.com/programming/apache_errors/[/url]

The errors I got were
notice: undefine index: HTTP_REFERER in “my dir location” on line 41.

notice: undefined variable: message in “my dir location” on line 131

Warning: mail() [function.mail]: Failed to connect to mailserver at “localhost” port 25, verify your “SMTP” and “smtp_port” setting in php.ini or use ini_set() in “my dir location” on line 140

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@FonsFeb 23.2010 — You have a reference in your pages looking to include files like a header.php?

your error pages have a different root_path than your normal website.

please paste some code if you can, makes it easier.

/Fons
Copy linkTweet thisAlerts:
@duceducauthorFeb 23.2010 — Thanks for the reply. I forgot to mentioned that I am very new setting up a home web server which I just did with wampserver. The instruction didn't mentioned anything about redirecting the header path. ?

When you said codes, what codes are you referring to?
Copy linkTweet thisAlerts:
@FonsFeb 23.2010 — The websites are made of code, html and php.

if you could post the source code of your error page, I might be able to help you more

/Fons
Copy linkTweet thisAlerts:
@duceducauthorFeb 23.2010 — Here is my errorpage.php code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/main_template_final.dwt" codeOutsideHTMLIsLocked="false" -->

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- InstanceBeginEditable name="doctitle" -->

<title>Duc Su</title>

<!-- InstanceEndEditable -->

<link href="stylesheets/mystylesheet.css" rel="stylesheet" type="text/css" />

<!-- InstanceBeginEditable name="head" -->

<!-- InstanceEndEditable -->

<!-- InstanceParam name="homeClass" type="text" value="holder" -->

<!-- InstanceParam name="portfolioClass" type="text" value="holder" -->

<!-- InstanceParam name="aboutClass" type="text" value="holder" -->

<!-- InstanceParam name="eventClass" type="text" value="holder" -->

<!-- InstanceParam name="contactClass" type="text" value="holder" -->

</head>

<body>

<div id="wrapper">

<div id="header">

<div id="logo"></div>

<div id="contactButton"><p><a href="mailto:[email protected]?subject=Info">contact</a></p></div>

<div id="mainNav">


<ul>

<li><a href="index.htm" class="holder">Home</a></li>

<li><a href="portfolio.htm" class="holder">Portfolio</a></li>

<li><a href="aboutme.htm" class="holder">About Me</a></li>

<li><a href="blog.htm" class="holder">Blog</a></li>

<li><a href="contact.htm" class="holder">Contact</a></li>

</ul>

</div>

<img src="images/header_bg.png" width="760" height="310" alt="ducsu" /></div>

<div id="bgHolder">

<div id="mainContent"><!-- InstanceBeginEditable name="main" --><?php

// Setup

$email = '[email protected]'; //Change to your e-mail address

// Get Variables

$error = $_SERVER['REDIRECT_STATUS'];

$referring_url = $_
SERVER['HTTP_REFERER'];

$requested_url = $_SERVER['REQUEST_URI'];

$referring_ip = $_
SERVER['REMOTE_ADDR'];

$server_name = $_SERVER['SERVER_NAME'];

$subject2 = "IP ONLY";

// Different error messages to display

switch ($error) {

# Error 400 - Bad Request


case 400:

$errorname = 'Error 400 - Bad Request';

$errordesc = '<h1>Bad Request</h1>

<h2>Error Type: 400</h2>

<p>

The URL that you requested — http://'.$server_name.$requested_url.' — does not exist on this server. You might want to re-check the spelling and the path.</p>

<p>

I apologize for any inconvenience caused and will do all I can to fix the error as soon as possible.</p>

<p>You can use the menu at the top of the page or at the right to navigate to another section.</p>';

break;

# Error 401 - Authorization Required


case 401:

$errorname = 'Error 401 - Authorization Required';

$errordesc = '<h1>Authorization Required</h1>

<h2>Error Type: 401</h2>

<p>

The URL that you requested requires pre-authorization to access.</p>

<p>

I will do all I can to fix it as soon as possible.</p>';

break;

# Error 403 - Access Forbidden


case 403:

$errorname = 'Error 403 - Access Forbidden';

$errordesc = '<h1>Access Forbidden</h1>

<h2>Error Type: 403</h2>

<p>

Access to the URL that you requested is forbidden.</p>

<p>

I will do all I can to fix it as soon as possible.</p>';

break;

# Error 404 - Page Not Found


case 404:

$errorname = 'Error 404 - Page Not Found';

$errordesc = '<h1>File Not Found</h1>

<h2>Error Type: 404</h2>

<p>

Ooops! The page you are looking for — http://'.$server_name.$requested_url.' — cannot be found. This may be because:</p>

<ul>

<li>the path to the page was entered wrong;</li>

<li>the page no longer exists; or</li>

<li>there has been an error on the Web site.</li>

</ul>

<p>

I apologize for any inconvenience caused and I will do all I can to fix the error as soon as possible.</p>

<p>You can use the menu at the top of the page navigate to another section.</p>';

break;

# Error 500 - Server Configuration Error


case 500:

$errorname = 'Error 500 - Server Configuration Error';

$errordesc = '<h1>Server Configuration Error</h1>

<h2>Error Type: 500</h2>

<p>

The URL that you requested — <a href="http://'.$server_name.$requested_url.'">http://'.$server_name.$requested_url.'</a> — resulted in a server configuration error. It is possible that the condition causing the problem will be gone by the time you finish reading this.</p>

<p>

I apologize for any inconvenience caused and I will do all I can to fix the error as soon as possible.</p>';

break;

# Unknown error


default:

$errorname = 'Unknown Error';

$errordesc = '<h2>Unknown Error</h2>

<p>The URL that you requested — <a href="http://'.$server_name.$requested_url.'">http://'.$server_name.$requested_url.'</a> — resulted in an unknown error. It is possible that the condition causing the problem will be gone by the time you finish reading this. </p>

<p> I apologize for any inconvenience caused and I will do all I can to fix the error as soon as possible.</p>';

}

// Display selected error message

echo($errordesc);

if (!$referring_url == '') {

echo '<p><a href="'.$referring_url.'"><< Go back to previous page.</a></p>';

} else {

echo '<p><a href="javascript:history.go(-1)"><< Go back to previous page.</a></p>';

}

// End of e-mail section.

?><!-- InstanceEndEditable --></div>

<div id ="sidebar"><!-- InstanceBeginEditable name="side" --><!-- InstanceEndEditable --></div>

<div id="clear"></div>

</div>

<div id="footer"> <p><a href="index.htm">Home</a> | <a href="portfolio.htm">Portfolio</a> | <a href="aboutme.htm">About Me</a> |<a href="blog.htm"> Blog</a> | <a href="contact.htm">Contact</a></p>

<p style="color: white; font-size: .8em;">Layout designed by Talk-Mania</p>

<p style="color: white; font-size: .8em;">All Rights Reserved. 2010</p>

</div>

</div>

</body>

<!-- InstanceEnd --></html>
[/QUOTE]

Here is my .htaccess
ErrorDocument 400 /errorpage.php

ErrorDocument 401 /errorpage.php

ErrorDocument 403 /errorpage.php

ErrorDocument 404 /errorpage.php

ErrorDocument 500 /errorpage.php[/QUOTE]
Copy linkTweet thisAlerts:
@duceducauthorFeb 24.2010 — The error message is this.

"Notice: Undefined index: HTTP_REFERER in K:wampwwwducsuerrorpage.php on line 41"

Line 41 is '$referring_url = $_SERVER['HTTP_REFERER'];'

// Setup

$email = '[email protected]'; //Change to your e-mail address

// Get Variables

$error = $_SERVER['REDIRECT_STATUS'];

$referring_url = $_
SERVER['HTTP_REFERER'];

$requested_url = $_SERVER['REQUEST_URI'];

$referring_ip = $_
SERVER['REMOTE_ADDR'];

$server_name = $_SERVER['SERVER_NAME'];

$subject2 = "IP ONLY";[/QUOTE]
Copy linkTweet thisAlerts:
@FonsFeb 24.2010 — after some reading up I found the following on http://php.net/manual/en/reserved.variables.server.php

The address of the page (if any) which referred the user agent to the current page. This is set by the user agent. Not all user agents will set this, and some provide the ability to modify HTTP_REFERER as a feature. In short, it cannot really be trusted.

As the only place you are using the param, i suggest to remove it from your code and change the function to a simple line being [code=php] echo '<p><a href="javascript:history.go(-1)"><< Go back to previous page.</a></p>';[/code]
This should do the trick in all cases, and by reading your source, you are providing a menu on the error page as well (or embed a link back to the mainpage)

Hope this will create a decent and nice looking error page

/Fons
Copy linkTweet thisAlerts:
@duceducauthorFeb 25.2010 — Thank you for your help. I fixed the line with your help, now I have another one that popped up.

error message:

Notice: Undefined variable: message in K:wampwwwducsuerrorerrorpage.php on line 133

Here is the line:

// E-mail section. Delete if you do not want to be sent e-mail notifications of errors.

$datetime = date("l, F d, Y - h:i:s A T");

$message .= '<i>The following error was received on '.$datetime.'</i>'; //<---line 133

$message .= '<br><br><b><i>'.$errorname.'</i></b>';

$message .= '<br><i>Requested URL:</i> <a href="http://'.$server_name.$requested_url.'">http://'.$server_name.$requested_url.'</a>';

$message .= '<br><i>Referring URL:</i> <a href="http://'.$referring_url.'">http://'.$referring_url.'</a>';[/QUOTE]
Copy linkTweet thisAlerts:
@FonsFeb 25.2010 — Wondering, did you try to name $datetime different?

Else it could be a error in the line above setting $datetime.

please paste some more code if it is not working yet

/Fons
Copy linkTweet thisAlerts:
@criterion9Feb 25.2010 — 
$message .= '<i>The following error was received on '.$datetime.'</i>'; //<---line 133
[/quote]

You are adding a value to an existing variable. If this is the first instance of that variable remove the "." and just have the "=" as in:
[code=php]
$message = '<i>The following error was received on '.$datetime.'</i>'; //<---line 133
[/code]
Copy linkTweet thisAlerts:
@duceducauthorFeb 25.2010 — Thanks guys for the help. Deleting the value "." removed the error.
×

Success!

Help @duceduc spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...