Custom Error Pages
Credits to css-tricks for some of the code.

Someone needed it so I figured it would be useful to a ton of more users, note this may not handle all errors but you can add to it with ease. I just threw this together so I'm sorry for any confusion.

Step 1: Upload the error.php file to our MyBB root folder, you can change the name if you want.


    define('IN_MYBB', 1);


	$codes = array(
	      400 => array('400 Bad Request', 'The request cannot be fulfilled due to bad syntax.'),
	      401 => array('401 Login Error', 'It appears that the password and/or user-name you entered was incorrect.'),
	      403 => array('403 Forbidden', 'Sorry, employees and staff only.'),
	      404 => array('404 Missing', 'We\'re sorry, but the page you\'re looking for is missing, hiding, or maybe it moved somewhere else and forgot to tell you.'),
	      405 => array('405 Method Not Allowed', 'The method specified in the Request-Line is not allowed for the specified resource.'),
	      408 => array('408 Request Timeout', 'Your browser failed to send a request in the time allowed by the server.'),
	      414 => array('414 URL To Long', 'The URL you entered is longer than the maximum length.'),
	      500 => array('500 Internal Server Error', 'The request was unsuccessful due to an unexpected condition encountered by the server.'),
	      502 => array('502 Bad Gateway', 'The server received an invalid response from the upstream server while trying to fulfill the request.'),
	      504 => array('504 Gateway Timeout', 'The upstream server failed to send a request in the time allowed by the server.'),

	$errortitle = $codes[$status][0];
	$message = $codes[$status][1];

	// Message that is displayed if an unknown error occurs or if they're viewing the error page directly.
	if( $errortitle == false ) {
	       $errortitle = "Unknown Error";
	       $message = "An unknown error has occurred.";

    add_breadcrumb($errortitle, "error.php");
    eval("\$html = \"".$templates->get("errors")."\";");


Step 2: Create a global template in your AdminCP named "errors" and paste/save the following code.

<title>{$mybb->settings['bbname']} - Error</title>
<table border="0" cellspacing="0" cellpadding="4" class="tborder">
<td class="thead" colspan="1"><strong>{$errortitle}</strong></td>
<td class="trow1">{$message}</td>

Step 3: You will need to use .htaccess to specify and handle the error documents. Expand as needed...

ErrorDocument 400 /error.php
ErrorDocument 401 /error.php
ErrorDocument 403 /error.php
ErrorDocument 404 /error.php
ErrorDocument 405 /error.php
ErrorDocument 408 /error.php
ErrorDocument 414 /error.php
ErrorDocument 500 /error.php
ErrorDocument 502 /error.php
ErrorDocument 504 /error.php


Messages In This Thread
Custom Error Pages - by Corey H - 2015-12-19, 09:09 AM
RE: Custom Error Pages - by RoD - 2015-12-19, 11:19 AM

Forum Jump:

Users browsing this thread: 1 Guest(s)