Integrated Error Messages

All new MODs released in our MOD Database will be announced in here. All support for released MODs needs to take place in the Customisations Database.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

NOTICE: This forum is only for the announcement of new releases and/or updates of MODs. Any MOD support should be obtained through the Customisations Database in the support area designated for each MOD.

A direct link to support for each MOD is in the first post of the respective topic.
User avatar
sevenalive
Translator
Posts: 437
Joined: Thu Feb 07, 2008 4:45 am
Location: Tempe, AZ
Name: Robert

Re: Integrated Error Messages

Post by sevenalive »

LOL your not going to believe this but your language/en/mods/error.php file has a spelling mistake.
Your installing the file into British english, however you spelled words in U.S. English.

Shouldn't it be Authorisation not Authorization? (i have en_us on my board since i am in the u.s, btw).

They shouldn't of validated it because of that lol.
User avatar
Phantom784
Registered User
Posts: 290
Joined: Wed Aug 08, 2007 3:09 am
Location: State College, PA
Contact:

Re: Integrated Error Messages

Post by Phantom784 »

That's what happens when an American like me attempts to use British English. I tried to make it British, but I guess I don't know everything about spelling like the Brits. :lol:

(Wouldn't life be so much simpler if Webster didn't have to go around and change the spellings for no good reason?)
Want to contact me? Find out how at http://francisfisher.com/contact.php
Dies
Registered User
Posts: 13
Joined: Tue May 13, 2008 5:55 pm

Re: Integrated Error Messages

Post by Dies »

Thanks for a simple, awesome little mod. :)

No more ugly, default apache pages anywhere....
Last edited by Dies on Mon Jun 09, 2008 5:29 pm, edited 1 time in total.
AllGo
Registered User
Posts: 12
Joined: Sun May 04, 2008 12:48 pm
Contact:

Re: Integrated Error Messages

Post by AllGo »

Is it possible for this MOD to set the HTTP Header status code to anything other than 200 (OK)?

For example: /error.php?mode=404 should set the HTTP Header status to 404 (Not found).
AllGo
Registered User
Posts: 12
Joined: Sun May 04, 2008 12:48 pm
Contact:

Re: Integrated Error Messages

Post by AllGo »

Fixed error.php to set the http error code correctly (for better behaviour with browsers and lots of crawler/search engines):

Code: Select all

<?php
/** 
*
* @package phpBB3
* @version $Id: $
* @copyright (c) 2008 Francis W. Fisher (Phantom) http://radoncube.com/
* @license http://opensource.org/licenses/gpl-license.php GNU Public License 
*
*/

/**
* @ignore
*/
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);

// Start session management
$user->session_begin();
$auth->acl($user->data);
$user->setup('mods/error');

$base_url = generate_board_url() . '/';

$template->assign_vars(array(
	'S_ERROR_PAGE'	=> true,
	'U_FORUM_BASE'	=> $base_url,
));

//set title of error page
$msg_title = $user->lang['ERROR_TITLE'];

$mode = request_var('mode', 0);

function HTTPStatus($num) {
  
   static $http = array (
       '100' => "HTTP/1.1 100 Continue",
       '101' => "HTTP/1.1 101 Switching Protocols",
       '200' => "HTTP/1.1 200 OK",
       '201' => "HTTP/1.1 201 Created",
       '202' => "HTTP/1.1 202 Accepted",
       '203' => "HTTP/1.1 203 Non-Authoritative Information",
       '204' => "HTTP/1.1 204 No Content",
       '205' => "HTTP/1.1 205 Reset Content",
       '206' => "HTTP/1.1 206 Partial Content",
       '300' => "HTTP/1.1 300 Multiple Choices",
       '301' => "HTTP/1.1 301 Moved Permanently",
       '302' => "HTTP/1.1 302 Found",
       '303' => "HTTP/1.1 303 See Other",
       '304' => "HTTP/1.1 304 Not Modified",
       '305' => "HTTP/1.1 305 Use Proxy",
       '307' => "HTTP/1.1 307 Temporary Redirect",
       '400' => "HTTP/1.1 400 Bad Request",
       '401' => "HTTP/1.1 401 Unauthorized",
       '402' => "HTTP/1.1 402 Payment Required",
       '403' => "HTTP/1.1 403 Forbidden",
       '404' => "HTTP/1.1 404 Not Found",
       '405' => "HTTP/1.1 405 Method Not Allowed",
       '406' => "HTTP/1.1 406 Not Acceptable",
       '407' => "HTTP/1.1 407 Proxy Authentication Required",
       '408' => "HTTP/1.1 408 Request Time-out",
       '409' => "HTTP/1.1 409 Conflict",
       '410' => "HTTP/1.1 410 Gone",
       '411' => "HTTP/1.1 411 Length Required",
       '412' => "HTTP/1.1 412 Precondition Failed",
       '413' => "HTTP/1.1 413 Request Entity Too Large",
       '414' => "HTTP/1.1 414 Request-URI Too Large",
       '415' => "HTTP/1.1 415 Unsupported Media Type",
       '416' => "HTTP/1.1 416 Requested range not satisfiable",
       '417' => "HTTP/1.1 417 Expectation Failed",
       '500' => "HTTP/1.1 500 Internal Server Error",
       '501' => "HTTP/1.1 501 Not Implemented",
       '502' => "HTTP/1.1 502 Bad Gateway",
       '503' => "HTTP/1.1 503 Service Unavailable",
       '504' => "HTTP/1.1 504 Gateway Time-out"       
   );
  
   header($http[$num]);
}
HTTPStatus($mode);
meta_refresh(5, $base_url);

switch ($mode)
{
	case '400':
   	trigger_error('ERROR_BAD_REQUEST');
	break;
	case '401':
		trigger_error('ERROR_AUTH_REQUIRED');
	break;
	case '403':
		trigger_error('ERROR_FORBIDDEN');
	break;
	case '404':
		trigger_error('ERROR_NOT_FOUND');
	break;
	case '500':
		trigger_error('ERROR_INT_SERVER');
	break;
	default:
		trigger_error('ERROR_UNKNOWN');
	break;
}

?>
User avatar
Phantom784
Registered User
Posts: 290
Joined: Wed Aug 08, 2007 3:09 am
Location: State College, PA
Contact:

Re: Integrated Error Messages

Post by Phantom784 »

It shouldn't be necessary for error.php to manually set the header status. Although accessing error.php directly will give an error code of 200 OK, when Apache uses it as the error document for a non-existent page, it knows to use the correct header (and I confirmed this with Wireshark). I'm assuming that it'll do this for other error statuses as well. I'm not sure how other web servers behave, although I'd expect them to do the same.
Want to contact me? Find out how at http://francisfisher.com/contact.php
AllGo
Registered User
Posts: 12
Joined: Sun May 04, 2008 12:48 pm
Contact:

Re: Integrated Error Messages

Post by AllGo »

Phantom784 wrote:It shouldn't be necessary for error.php to manually set the header status. Although accessing error.php directly will give an error code of 200 OK, when Apache uses it as the error document for a non-existent page, it knows to use the correct header (and I confirmed this with Wireshark). I'm assuming that it'll do this for other error statuses as well. I'm not sure how other web servers behave, although I'd expect them to do the same.
Weird.. Both on my local development machine (Debian Unstable with apache 2.2.8 package), and the website host (apache someversion on centos) the error pages returned 200 OK.

I'd like to hear from other people who have installed this mod :).

(I used wget http://www.myexample.net/randomnonexistantpath, to check, if it downloads the page, the page sent 200 OK, otherwise wget should complain about 404 Not Found...)
Dies
Registered User
Posts: 13
Joined: Tue May 13, 2008 5:55 pm

Re: Integrated Error Messages

Post by Dies »

wget http://www.redcellso.com/forums/dontexist
--19:12:59-- http://www.redcellso.com/forums/dontexist
=> `dontexist'
Resolving www.redcellso.com...
Connecting to www.redcellso.com||:80... connected.
HTTP request sent, awaiting response... 404 Not Found
19:12:59 ERROR 404: Not Found.
User avatar
Spider M. Mann
Registered User
Posts: 73
Joined: Sat Dec 01, 2007 3:06 pm

Re: Integrated Error Messages

Post by Spider M. Mann »

@Phantom:

I've installed your great MOD on my site, and all works well, except for one strange anomaly: If I try to go to "pagedoesnotexist.php," "No input file specified." is returned. However, if I go to "pagedoesnotexist.html" it functions as expected.

Any ideas? My site is http://www.shadowcaste.com/ if you'd like to check it out.

Thanks for any input you can give.
User avatar
MartectX
Translator
Posts: 1324
Joined: Wed Dec 19, 2007 8:05 pm
Location: Marienplatz

Re: Integrated Error Messages

Post by MartectX »

Spider M. Mann wrote:@Phantom:

I've installed your great MOD on my site, and all works well, except for one strange anomaly: If I try to go to "pagedoesnotexist.php," "No input file specified." is returned. However, if I go to "pagedoesnotexist.html" it functions as expected.

Any ideas? My site is http://www.shadowcaste.com/ if you'd like to check it out.

Thanks for any input you can give.
Woops, now that you mention it: I get the standard 404 of my host when I try accessing a non-existant .php file; only for every other extension I get the custom 404!
User avatar
Phantom784
Registered User
Posts: 290
Joined: Wed Aug 08, 2007 3:09 am
Location: State College, PA
Contact:

Re: Integrated Error Messages

Post by Phantom784 »

I'm guessing that the problem with non-existent php files has something to do with the way your server is configured. You should probably talk to your host about why this is happening.
Want to contact me? Find out how at http://francisfisher.com/contact.php
User avatar
Ddraiggoch06
Registered User
Posts: 482
Joined: Sun May 18, 2008 11:45 am
Location: Wales, UK

Re: Integrated Error Messages

Post by Ddraiggoch06 »

Brilliant MOD, just what I was looking for. Thank you :D
I accept PM support for phpBB3. Please do not PM me with MOD or Style support and requests.
"Give a man a fish and you'll have fed him for today. Teach a man to fish and you'll have fed him for a lifetime."
User avatar
Spider M. Mann
Registered User
Posts: 73
Joined: Sat Dec 01, 2007 3:06 pm

Re: Integrated Error Messages

Post by Spider M. Mann »

Phantom784 wrote:I'm guessing that the problem with non-existent php files has something to do with the way your server is configured [...]
You are correct. It seems to be a known issue when using php5.

404 (not found) condition for php scripts does not go to 404 error handling. You will instead get this error message:
No input file specified.

I think I solved it with a little mod_rewrite hackery by putting the following code into my .htaccess file:

Code: Select all

RewriteEngine On
Rewritecond %{REQUEST_FILENAME} !-f
RewriteRule \.php$ /error.php?mode=404
Note: This is a fix for when using the "Integrated Error Messages" mod. If you're not using the mod, change "/error.php?mode=404" to "/error404.html" or whatever your custom 404 file is named.

!-f checks to see if the requested .php location exists and is a real file. If not, the rewrite rule will direct to the chosen error document. The only real drawback I can see is that it'll mess with requests for things other than real files -- notably, symlinks.

I hope this helps anyone else who may run into this issue. Phantom784, I apologize for lumping this issue in with your great MOD, as it was not the problem. However, it did allow me to discover the condition, and this seemed like the best place to post the solution.

Thanks for your time.
User avatar
MartectX
Translator
Posts: 1324
Joined: Wed Dec 19, 2007 8:05 pm
Location: Marienplatz

Re: Integrated Error Messages

Post by MartectX »

That did it! Kudos to you, Mr. Mann! :ugeek:
User avatar
Phantom784
Registered User
Posts: 290
Joined: Wed Aug 08, 2007 3:09 am
Location: State College, PA
Contact:

Re: Integrated Error Messages

Post by Phantom784 »

Although Spider M. Mann's solution will work, when you go to a non-existent .php file, the page will return as 200 OK instead of 404 FILE NOT FOUND (unless you use AllGo's error.php file, posted earlier in this topic.) To prevent this, you can simply mod-rewrite to a non-existant file, and then apache will send the user to error.php, including the correct header. (This idea from jenseng.com)
Want to contact me? Find out how at http://francisfisher.com/contact.php
Locked

Return to “[3.0.x] MOD Database Releases”