petak, 21. prosinca 2007.

Custom Error Pages

Creating custom error pages in PHP Fusion is easy. This article shows you how to create a custom 404 'page not found' error page but it can easily be modified to create pages for other ErrorDocument codes.

If have applied the page title optimisation mod your visitor will be presented with an informative page which matches the theme of your site AND which also has a HTML title tag of your choosing.

Step 1: Download the code for 404.php from the CVS Browser (click the disk).

Step 2: Edit and modify 404.php to meet your requirements.

Step 3: Upload 404.php to the root directory of your PHP Fusion installation.

Step 4: Create a .htaccess file if you don't already have one and add the following to it.

## Forbidden
ErrorDocument 404 /404.php

That's it - your done!

To create pages for other ErrorDocument codes: Download 404.php and rename it to whatever error code you have in mind and modify your .htaccess file accordingly. Possible inclusions are:

## Bad Request
ErrorDocument 400 /400.php

## Unauthorized
ErrorDocument 401 /401.php

## Payment Required
ErrorDocument 402 /402.php

## Forbidden
ErrorDocument 403 /403.php

## Not Found
ErrorDocument 404 /404.php

## Server Error
ErrorDocument 500 /500.php

## Bad Gateway
ErrorDocument 502 /502.php

For a more complete list view the HTTP/1.1 Status Code Definitions at

ponedjeljak, 17. prosinca 2007.

This custom error page shows some standard error information and reports the error to the webmaster by e-mail.

/* create a .htaccess file in your root and enter these most common error code definitions

ErrorDocument 400 /error.php?err=400
ErrorDocument 401 /error.php?err=401
ErrorDocument 403 /error.php?err=403
ErrorDocument 404 /error.php?err=404
ErrorDocument 500 /error.php?err=500


// save this code below in file name "error.php"
if (isset($_GET['err'])) {
$errorNum = $_GET['err'];
} else {
$errorNum = "undef. number";

$emailaddress = "";
you have to create this file and enter there all URL's with bad links and
all IP addresses which are hot linking not existing files, example:

$filename = "http://".$_SERVER['HTTP_HOST']."/blocked_ref.txt";

// if the http referer is not empty check the file for exsiting URL's
if (!empty($_SERVER['HTTP_REFERER'])) {
$bad_ref = file ($filename);
$bad_counter = 0;
foreach ($bad_ref as $val) {
if (substr($_SERVER['HTTP_REFERER'], 0, 20) == substr($val, 0, 20)) {
if ($bad_counter > 0) {
header("Location: http://".$_SERVER['HTTP_HOST']);
} else {
$errortime = (date("d M Y h:m:s"));
$message = $errorNum." Error Report\r\n\r\nA ".$errorNum." error was encountered by ".$_SERVER['REMOTE_ADDR'];
$message .= " on $errortime.\r\n\r\n";
$message .= "The URI which generated the error is: \nhttp://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']."\r\n\r\n";
$message .= "The referring page was:\n".$_SERVER['HTTP_REFERER']."\r\n\r\n";
$message .= "The used client was:\n".$_SERVER['HTTP_USER_AGENT']."\r\n\r\n";
$headers = "From: ".$emailaddress."\nDate: ".$errortime." +0100\n";
$subject = "Error: ".$errorNum." from ".$_SERVER['HTTP_REFERER'];
mail($emailaddress, $subject, $message, $headers);
} else { // at last check if there are already some bad IP Addresses
$bad_ref = file ($filename);
$very_bad_counter = 0;
foreach ($bad_ref as $val) {
if (substr($_SERVER['REMOTE_ADDR'], 0, 10) == substr($val, 0, 10)) {
if ($very_bad_counter > 0) {
header("Location:"); // or some other nice URL
// place here the html code you want to show the visitor, like
echo "

Some error...


nedjelja, 9. prosinca 2007.

redirect a visitor to

Here's an example on how to redirect a visitor to


The above example shows how to redirect the visitor to a static address. You can also dynamically create the location to which the visitor is to be redirected.

$redirectstr= $domain.$querystring;
header('Location:'. $redirectstr);

The above code will create the URL for redirection as and then redirect them to the URL. You can also build php code which can conditionally redirect a page. See how this is done in the following example.


četvrtak, 29. studenoga 2007.

404 error page

the 404 error page works fine with this

Nm. 2 Php error pages

When accessing valid pages from Apache2 server, PHP comes back with No
input file specified. Logs show a page was correctly accessed, but with
a 404 error code. Specifying a .html file or a non-existant file,
returns a valid page or a 404 error page correcty.
I believe the problem lies in the PHP fastcgi daemon some how. I
believe I have removed all other possible problems.

I'm confused: I have recompiled PHP5 and Apache2 removing everything
that seems unneccesary
I have PHP5 compiled using
./configure --enable-fastcgi --prefix=/usr/local/php5
--program-suffix=-fastcgi --without-pear and running as a separate
daemon using -b
I have Apache2 compiled with ./configure --prefix=/usr/local/apache2
Apache2 Config portion is below

/usr/local/apache2/fastcgi is a valid, but empty directory

I had the server working at one point, but I added a few compile options
and it stopped, and I've since removed all but the basic compile options
and it still dies.

I have done a make clean before building and I have tried this from the
original clean tarball sources.

I'm clueless. I'm not used to this kind of problem under Linux.

Reproduce code:
Apache2 Config, which I had problems figuring out.

LoadModule fastcgi_module modules/

Alias /fcgi-bin/ /usr/local/apache2/fastcgi/
FastCGIExternalServer /usr/local/apache2/fastcgi/php-fastcgi -host
AddType application/x-httpd-fastphp .php
Action application/x-httpd-fastphp /fcgi-bin/php-fastcgi

Expected result:
Apache Works fine except for when defering requests to the PHP daemon.

Something, Anything from the PHP daemon. Even an error code would be
nice. If I point it at a .html file with a .php extension just
containing 'Hello World' it still returns "No input file specified"

It would be handy if the php -b daemon could log some indication as to
what it was doing to the console its running on. This seems a noticable
ommission for a daemon (normally -D makes a daemon single action and
debug to screen).

srijeda, 28. studenoga 2007.

Typicall problem with server error page 404

When running PHP as a CGI binary on Apache, you might get the above error if you request a nonexistent PHP file. If you've got a custom 404 page (or even the default one), this can be irritating, as it makes for an inconsistent user experience (although a good site (re)design should never be a catalyst of 404 errors).

The reason this happens is that any requests ending in .php are simply handed off to the PHP executable without verifying that such a file exists. Although this is by design, it can be a bit offputting. Unfortunately, there does not appear to be a way to configure the PHP executable to return a "normal" 404 to Apache if the requested script does not exist. True, it does return a 404 response header along with the "No input file specified", but it won't return the appropriate ErrorDocument under any circumstances.

Google didn't come up with any solutions, although it did find many other people with the same problem.

Luckily for me, I had spent the last few days playing around with mod_rewrite, and it occurred to me that that's how to solve the problem. Mod rewrite is an extremely powerful Apache module that lets you manipulate/redirect urls. In short, if you want to prevent hotlinking, protect content, optimize for search engines, do load balancing, or just about anything you can think of when it comes to urls, then mod_rewrite is for you.

So getting back on topic, all we have to do is create a simple rewrite rule that checks the requested url to see if 1. it is ends in .php and 2. no such file exists. If both conditions are met, we translate the request into a url that we know doesn't exist. This triggers a 404, and Apache sends the client the appropriate ErrorDocument. Rewrite rules are run before anything is sent off to the content handler, so PHP is bypassed entirely.

It's simply a matter of putting an .htaccess file in our base dir with the following lines:

RewriteEngine On
RewriteRule ^.+\.php$ /bogusfile

And that's it! Your mileage may vary, since not all servers are configured identically. Just be sure that /bogusfile really doesn't exist, otherwise it will be served up instead of the 404.

Update 2005-01-20 10:55 AM
It appears my google skills are lacking. Someone known as n74 solved this about two months ago ... here and here...

The only difference is that his solution rewrites the url to the ErrorDocument, whereas mine rewrites it to a nonexistent file.

The end result is the same, except that his way a 200 status code is sent rather than a 404.


If you have any questions please ask here or on my private mail. Remember, there is no stupid question, only stupid answer.


Hello people,
as you can see, I've started a blog about php error pages. :-)

Sopranos Ruby Css Xhtml Cgi Calabria Rocky Oktoberfest Fencing