Trading Systems Analyst (IL)
Next Step Systems
US-IL-Chicago

Justtechjobs.com Post A Job | Post A Resume

Using PHP Error Handling
An all to common error on the web is broken links. You end up with broken links from other sites whenever you rearrange your site. People bookmark some page they like and come back 3 months later only to find a '404 Not Found', giving them no help whatsoever about where to start looking for the page you originally had on your site. Let's solve this, or atleast be friendly to your users and help them get back on track whenever they hit 'a 404'. You can even create a common page to report all errors you might encounter while rendering your pages.
PHP together with Apache gives you quite alot of freedom to create your own error pages, but requires some reconfiguring and a tiny bit of coding. Let's start off with the configuration part.
The Apache ErrorDocument directive specifies what document (or URI) Apache should redirect a user to in case of an error. It allows you to specify one resource for each and every error code one of your users might run into. Start off by adding a ErrorDocument 404 /error.php directive to your server configuration. This will redirect users that ask for a page that does not exist to the 'error.php' page you will soon write. Don't forget to restart Apache for the changes to take effect.
Next, we write up a very simple error.php:
The file you requested (<?=$REDIRECT_URL?>) does not exist on this server.
Please look for the page you wanted at <A HREF="/">the front page</A>.
Now try to access a page that doesn't exist on your server, and voila, you're at the error.php page with a nice and friendly message and a link to your front page!
Let's extend this. As you can see, I used the REDIRECT_URL variable on the error.php page. This is a variable that Apache sets whenever it invokes an ErrorDocument directive, and gives you a possibility to find the originating resource whenever there's an error. Apache also sets a number of other variables in this case, all of them documented here. Use these variables to create a nice error page that gives your users a nice and friendly error page instead of the good ol' boring Apache default page.
[ Next Page ]


Comments:
Retrieve Javascript value in same php filesaravanan10/19/05 22:35
ereg functionBalaji09/11/05 10:29
PLEASE HELPkenneth07/26/05 22:35
php context menusugeeth03/07/05 00:45
RE: Server ErrorMAGnUm06/25/03 15:12
Not the best way to handle errorsKeith Ganger11/25/02 12:57
RE: Update Database ORACLEyongyut10/13/02 07:41
0 for $REDIRECT_URL for every page!coda10/02/02 05:06
php chat scriptsjaryd09/30/02 07:38
Apache subdomain helpJoseph09/19/02 11:52
php in netscape ??Jean Pierre09/02/02 15:45
PHP/PostgreSQL file upload/open script mike08/16/02 06:50
a PHP file?Dave the warrior06/12/02 07:39
RE: Java Script and PHPderek05/30/02 00:47
php file exist check on serverAnushree05/23/02 02:24
Error handling when page not foundAnushree05/22/02 10:01
TNS: no listenermaurice05/20/02 22:22
update oracle database , how?Melissa04/18/02 14:13
RE: PHP File Upload-please help meDrDre04/10/02 07:21
session function(php4)calistan thaya04/07/02 17:39
questionrdm03/11/02 23:42
Server ErrorArun02/27/02 07:05
RE: Forcing IE5 to accept your error pageYuzree Esmera02/10/02 08:08
REQUEST)URI and REDIRECT_URL are empty ?!?Alexandre Danault02/09/02 16:21
.php Steven12/14/01 22:11
RE: Handle ExceptionsSaravanan 12/12/01 00:39
RE: subdomain error handlingCraig12/10/01 11:32
RE: REDIRECT_URL pointed to processing scriptAdes11/21/01 19:25
RE: can i download an error script anywhere?Mark Fleming10/23/01 13:40
RE: PHP File Upload-please help meSaravanan 10/04/01 01:40
Update Database ORACLEFelix10/03/01 02:45
Java Script and PHPFelix10/03/01 02:44
PHP File Upload-please help meSaravanan 10/03/01 01:18
RE: Forcing IE5 to accept your error pageEric09/20/01 04:10
RE: server excludedJoffrey van Wageningen09/13/01 06:00
server excludedPeter van Beelen09/08/01 08:43
RE: REDIRECT_URL pointed to processing scriptSarah08/31/01 01:10
REDIRECT_URL pointed to processing scriptAngCK08/09/01 01:06
premature script header errorsatish07/21/01 05:05
RE: subdomain error handlingMorten Gade Sørensen07/17/01 10:25
RE: subdomain error handlingMarco DT07/16/01 09:13
RE: subdomain error handlingJade07/05/01 20:44
RE: subdomain error handlingAdam Miller07/05/01 15:34
can i download an error script anywhere?XTJ706/29/01 07:43
subdomain error handlingNathan Burke06/12/01 05:40
RE: Forcing IE5 to accept your error page*KWUK*05/29/01 00:00
Great!!!!!!!!Sarah05/27/01 09:52
Handle ExceptionsJailton Oliveira05/07/01 15:22
RE: Forcing IE5 to accept your error pagefryguy03/10/01 21:09
Forcing IE5 to accept your error pageGeoff Caplan11/13/00 13:55
 

If you are looking for help, please post on the appropriate forum here. Your questions will be answered much more quickly.

Add A Comment:

Name:

Email:

Subject:

Message:

To reduce spam posts, messages are now manually approved

You are not [logged in]. That means your account will not get credit for this post.