Home arrow PHP arrow Page 10 - Time Is Money (part 2)

When Things Go Wrong - PHP

In this concluding article, explore the scripts which add andremove timesheet entries to the system, and get a crash course instatistics by using these entries to generate useful resource allocationand usage reports.

TABLE OF CONTENTS:
  1. Time Is Money (part 2)
  2. Getting Creative
  3. Split Personality
  4. In...
  5. ...And Out
  6. The Number Game
  7. Exercising Restraint
  8. The Big Picture...
  9. ...And The Little Brush Strokes
  10. When Things Go Wrong
  11. Happy Endings
By: The Disenchanted Developer, (c) Melonfire
Rating: starstarstarstarstar / 4
November 16, 2001

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
The last script - another extremely simple one - is the error handler, "error.php". If you look at the source code, you'll notice many links to this script, each one passing it a cryptic error code via the $ec variable. Very simply, "error.php" intercepts the variable and converts it to a human-readable error message, which is then displayed to the user.

<? // error.php - displays error messages based on error code $ec // includes include("config.php"); include("functions.php"); switch ($ec) { // login failure case 0: $message = "There was an error logging you in. <a href=index.html>Please try again.</a>"; break; // session problem case 1: $message = "There was an authentication error. Please <a href=index.html>log in</a> again."; break; // bad datestamp case 2: $message = "You selected an invalid date range. Please <a href=menu.php>try again</a>."; break; // default action default: $message = "There was an error performing the requested action. Please <a href=index.html>log in</a> again."; break; } ?> <html> <head> <basefont face="Verdana"> <style type="text/css"> TD {font-family: Verdana; font-size: smaller} </style> </head> <body bgcolor="White"> <? $title="Error!"; ?> <? include("header.inc.php"); ?> <? echo $message; ?> <? include("footer.inc.php"); ?> </body> </html>
Here's what it looks like.



Simple and elegant - not to mention flexible. Found a new error? No problem - assign it an error code and let "error.php" know.

 
 
>>> More PHP Articles          >>> More By The Disenchanted Developer, (c) Melonfire
 

blog comments powered by Disqus
   

PHP ARTICLES

- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap

Dev Shed Tutorial Topics: