Page 3 of 7

Re: Integrated Error Messages

Posted: Sat May 17, 2008 3:04 am
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.

Re: Integrated Error Messages

Posted: Sun May 18, 2008 2:54 pm
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?)

Re: Integrated Error Messages

Posted: Thu May 22, 2008 3:19 pm
by Dies
Thanks for a simple, awesome little mod. :)

No more ugly, default apache pages anywhere....

Re: Integrated Error Messages

Posted: Sat May 24, 2008 12:25 pm
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).

Re: Integrated Error Messages

Posted: Sun May 25, 2008 2:52 pm
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;
}

?>

Re: Integrated Error Messages

Posted: Sun May 25, 2008 5:43 pm
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.

Re: Integrated Error Messages

Posted: Mon May 26, 2008 7:40 pm
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...)

Re: Integrated Error Messages

Posted: Mon May 26, 2008 11:17 pm
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.

Re: Integrated Error Messages

Posted: Wed May 28, 2008 11:33 am
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.

Re: Integrated Error Messages

Posted: Wed May 28, 2008 12:10 pm
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!

Re: Integrated Error Messages

Posted: Wed May 28, 2008 9:05 pm
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.

Re: Integrated Error Messages

Posted: Wed May 28, 2008 9:30 pm
by Ddraiggoch06
Brilliant MOD, just what I was looking for. Thank you :D

Re: Integrated Error Messages

Posted: Thu May 29, 2008 4:43 am
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.

Re: Integrated Error Messages

Posted: Thu May 29, 2008 9:43 am
by MartectX
That did it! Kudos to you, Mr. Mann! :ugeek:

Re: Integrated Error Messages

Posted: Thu May 29, 2008 7:36 pm
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)