Writing /home/kusabax/domains/kusabax.org/public_html/wiki/data/cache/9/9e0a84b7a7c6f706b617fc9ca581d475.i failed
Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.
Writing /home/kusabax/domains/kusabax.org/public_html/wiki/data/cache/9/9e0a84b7a7c6f706b617fc9ca581d475.metadata failed
Writing /home/kusabax/domains/kusabax.org/public_html/wiki/data/cache/9/9e0a84b7a7c6f706b617fc9ca581d475.i failed
Unable to save cache file. Hint: disk full; file permissions; safe_mode setting.
Writing /home/kusabax/domains/kusabax.org/public_html/wiki/data/cache/9/9e0a84b7a7c6f706b617fc9ca581d475.xhtml failed

Custom 404 Page

Here's a semi-intermediate level mod to give your site a nice little 404 page. For those somewhat familiar with the software, you'll notice that this is an edit of news.php and news.tpl to show a 404 page with a random image.


*Ability to create a directory *Ability to create php files *404 Images

Step 1

1. Make a directory called /404 2. Place images in that directory

Step 2 - Rotation Script

Create r.php with the following code and place it in /404

By Matt Mullenweg > http://photomatt.net
Inspired by Dan Benjamin > http://hiveware.com/imagerotator.php
Latest version always at:
*/// Make this the relative path to the images, like "../img" or "random/images/".
// If the images are in the same directory, leave it blank.
$folder = './img/';
// Space seperated list of extensions, you probably won't have to change this.
$exts = 'jpg jpeg png gif';
$files = array(); $i = -1; // Initialize some variables
if ('' == $folder) $folder = './';
$handle = opendir($folder);
$exts = explode(' ', $exts);
while (false !== ($file = readdir($handle))) {
foreach($exts as $ext) { // for each extension check the extension
if (preg_match('/\.'.$ext.'$/i', $file, $test)) { // faster than ereg, case insensitive
$files[] = $file; // it's good
closedir($handle); // We're not using it anymore
mt_srand((double)microtime()*1000000); // seed for PHP < 4.2
$rand = mt_rand(0, $i); // $i was incremented as we went along
header('Location: '.$folder.$files[$rand]); // Voila!
Step 2 - 404 Template

Now we make 404.tpl to place in /dwoo/templates/ (be sure to change Mikuchan to something else!)

<!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" xml:lang="en" lang="en"> 
<script type="text/javascript">
  var _gaq = _gaq || [];
  _gaq.push(['_setAccount', 'UA-17167947-1']);
  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	<title>Mikuchan - 404</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	{for style $styles}
				<link rel="{if $styles[$style] neq $dwoo.const.KU_DEFAULTMENUSTYLE}alternate {/if}stylesheet" type="text/css" href="{$dwoo.const.KU_WEBFOLDER}css/site_{$styles[$style]}.css" title="{$styles[$style]|capitalize}" />
<script type="text/javascript"><!--
	var style_cookie_site = "kustyle_site";
<link rel="shortcut icon" href="{$dwoo.const.KU_WEBFOLDER}favicon.ico" />
<script type="text/javascript" src="{%KU_WEBFOLDER}lib/javascript/gettext.js"></script>
<script type="text/javascript" src="{$dwoo.const.KU_WEBFOLDER}lib/javascript/kusaba.js"></script>
	{if $dwoo.const.KU_SLOGAN neq ''}<h3>{$dwoo.const.KU_SLOGAN}</h3>{/if}
	<div class="menu" id="topmenu">
			<li class="{if $dwoo.get.p eq ''}current {else}tab {/if}first">{if $dwoo.get.p neq ''}<a href="{$ku_webpath}news.php">{/if}{t}News{/t}{if $dwoo.get.p neq ''}</a>{/if}</li>
			<li class="{if $dwoo.get.p eq 'faq'}current{else}tab{/if}">{if $dwoo.get.p neq 'faq'}<a href="{$ku_webpath}news.php?p=faq">{/if}{t}FAQ{/t}{if $dwoo.get.p neq 'faq'}</a>{/if}</li>
			<li class="{if $dwoo.get.p eq 'rules'}current{else}tab{/if}">{if $dwoo.get.p neq 'rules'}<a href="{$ku_webpath}news.php?p=rules">{/if}{t}Rules{/t}{if $dwoo.get.p neq 'rules'}</a>{/if}</li>
		<br />
	<div class="content">
<center><strong><big><big><big>404 - Page Not Found</big></big></big></strong><br>
  <img src="{$ku_webpath}/404/r.php" alt="404"
              style="border: dashed black; border-radius: 1px;" /></a></center>
	</div><br />
Step 4 - 404 Script

Next, we make 404.php

 * This file is part of kusaba.
 * kusaba is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 * kusaba is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License along with
 * kusaba; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
 * News display, which is the first page shown when a user visits a chan's index
 * Any news added by an administrator in the manage panel will show here, with
 * the newest entry on the top.
 * @package kusaba
// Require the configuration file
require 'config.php';
require KU_ROOTDIR . 'inc/functions.php';
require_once KU_ROOTDIR . 'lib/dwoo.php';
$dwoo_tpl = new Dwoo_Template_File(KU_TEMPLATEDIR . '/404.tpl');
$topads = $tc_db->GetOne("SELECT code FROM `" . KU_DBPREFIX . "ads` WHERE `position` = 'top' AND `disp` = '1'");
$botads = $tc_db->GetOne("SELECT code FROM `" . KU_DBPREFIX . "ads` WHERE `position` = 'bot' AND `disp` = '1'");
$dwoo_data->assign('topads', $topads);
$dwoo_data->assign('botads', $botads);
if (!isset($_GET['p'])) $_GET['p'] = '';
if ($_GET['p'] == 'faq') {
	$entries = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "front` WHERE `page` = 1 ORDER BY `order` ASC");
} elseif ($_GET['p'] == 'rules') {
	$entries = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "front` WHERE `page` = 2 ORDER BY `order` ASC");
} else {
	$entries = $tc_db->GetAll("SELECT * FROM `" . KU_DBPREFIX . "front` WHERE `page` = 0 ORDER BY `timestamp` DESC");
$styles = explode(':', KU_MENUSTYLES);
$dwoo_data->assign('styles', $styles);
$dwoo_data->assign('ku_webpath', getCWebPath());
$dwoo_data->assign('entries', $entries);
$dwoo->output($dwoo_tpl, $dwoo_data);
Final Step - .htaccess

Open up .htaccess and find

DirectoryIndex kusaba.php

add below

ErrorDocument 404 /404.php

And we're finished! From here, you can change the variables to make other error code pages if you want.

404_page.txt · Last modified: 2011/06/01 16:40 by sazpaimon
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki