Jump to content

Custom Error Pages?


Xarcell

Recommended Posts

Nevermind, after some research, and updating some code in some scripts by various members, I managed to make custom error pages. I'll share with you what I have so that others by benefit from it. This can be done in 5 easy steps, with no coding knowledge required.

 

1.| Create a "error.php" file with this as it's contents:

 

<?php

define("CLIENTAREA",true);
//define("FORCESSL",true); # Uncomment to force the page to use https://

require("dbconnect.php");
require("includes/functions.php");
require("includes/clientareafunctions.php");

$pagetitle = $_LANG['clientareatitle'];
$breadcrumbnav = '<a href="index.php">'.$_LANG['globalsystemname'].'</a>';
$breadcrumbnav .= ' > <a href="error.php">Whoops!</a>'; 

initialiseClientArea($pagetitle,'',$breadcrumbnav);

# To assign variables to the template system use the following syntax.
# These can then be referenced using {$variablename} in the template.

$smartyvalues["variablename"] = $value; 

# Check login status
if ($_SESSION['uid']) {

 # User is logged in - put any code you like here

 # Here's an example to get the currently logged in clients first name

 $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".(int)$_SESSION['uid']);
 $data = mysql_fetch_array($result);
 $clientname = $data[0];
 $smartyvalues["clientname"] = $clientname;

} else {

 # User is not logged in

}

# Define the template filename to be used without the .tpl extension

$templatefile = "error"; 

$referer = $HTTP_REFERER;
$smarty->assign("refer", $referer);
switch($e)
{
default:
$e="404";
break;
case '400':
$e="400";
break;
case '401':
$e="401";
break;
case '403':
$e="403";
break;
case '404':
$e="404";
break;
case '500':
$e="500";
break;
case '503':
$e="503";
break;
}
$smarty->assign("e", "$e");

outputClientArea($templatefile);

?>

 

2.| Upload the "error.php" file to your WHMCS "root" directory.

 

3.| Create a "error.tpl" file with this as it's contents:

 

<div class="page-header">
   <div class="styled_title"><h1>Whoops! <small>Sometimes these things happen...</small></h1></div>
</div>

{if $e==400}
<h2>Error 400</h2><p>The server made a bad request. Please try again later. Thank you.</p>
{/if}

{if $e==401}
<h2>Error 401</h2><p>You need authorization to proceed beyond this point. If you forgot your password or username, you'll need to notify my <a href=/contact.php>admin</a>. Thanks</p>
{/if}

{if $e==403}
<h2>Error 403</h2><p>.Permission Denied.<br>I'd love to give you permission, but you see, my owner has requested this specific file is off limits to you. I can even show you the request.</p>
{/if}

{if $e==404}
Referrer: {$refer}
<h2>Error 404</h2><p>The file requested does not exist on this server. Perhaps you forgot the filename. Perhaps this was moved, and the <a href={$refer}>referring page</a> should be notified.If you were looking for the order page, that can be found <a href=/order.php>here</a>.</p>
{/if}

{if $e==500}
<h2>Error 500</h2><p>Something has gone wrong with one of my scripts and I'm clueless as to what. Maybe my logs will contain a bit more information.</p>
{/if}

 

4.| Upload the "error.tpl" file to your "template/YOUR-THEME-USED" directory.

 

5.| Add these lines to your .htaccess file(a hidden file in your WHMCS root):

 

#RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 404 /error.php?e=404
ErrorDocument 500 /error.php?e=500

 

Done. Enjoy!

Link to comment
Share on other sites

  • 2 months later...
  • 2 weeks later...
  • 3 months later...

Here the error.php updated for version 5.2

 

<?php

define("CLIENTAREA",true);
//define("FORCESSL",true); // Uncomment to force the page to use https://

require("init.php");

$ca = new WHMCS_ClientArea();

$ca->setPageTitle("Error");

$ca->addToBreadCrumb('index.php',$whmcs->get_lang('globalsystemname'));
$ca->addToBreadCrumb('error.php','Error');

$ca->initPage();

//$ca->requireLogin(); // Uncomment this line to require a login to access this page

# To assign variables to the template system use the following syntax.
# These can then be referenced using {$variablename} in the template.

$ca->assign('variablename', $value);


# Check login status
if ($ca->isLoggedIn()) {

  # User is logged in - put any code you like here

  # Here's an example to get the currently logged in clients first name

  $result = mysql_query("SELECT firstname FROM tblclients WHERE id=".$ca->getUserID());
  $data = mysql_fetch_array($result);
  $clientname = $data[0];

  $ca->assign('clientname', $clientname);

} else {

  # User is not logged in

}

# Define the template filename to be used without the .tpl extension

$ca->setTemplate('error');

$referer = $HTTP_REFERER;
$smarty->assign("refer", $referer);
switch($e)
{
default:
$e="404";
break;
case '400':
$e="400";
break;
case '401':
$e="401";
break;
case '403':
$e="403";
break;
case '404':
$e="404";
break;
case '500':
$e="500";
break;
case '503':
$e="503";
break;
}

$ca->assign("e", "$e");

$ca->output();

?>

Link to comment
Share on other sites

  • 3 months later...

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated