• Log in or sign up for an account here: https://www.sythe.org/login

[TUT] Custom Error Handling ( PHP )

Puzzle

Apprentice
Joined
May 6, 2005
Sythe Gold
0
Messages
846
[TUT] Custom Error Handling ( PHP )
Ok so everyone here would probably agree with me that PHP's default method of displaying your errors isn't very friendly at times so i thought why not tell you guys how to make your own function that does the SAME thing as the php error but in a more please able format.

Lets get started, im assuming that everyone here has some basic php knowledge or else you shouldn't be reading this. First thing you must do is add this function somewhere on your page

Code:
<?php
      function errhandle($errnum, $errmsg, $errfile, $errline, $errcntxt) // only the first two parameters error number and error message must be used, the other 3 are optional.
	    {
		echo "<b>Error Number: $errnum<br>";
		echo "<b>Reason: $errmsg<br>";
		echo "<b>File: $errfile<br>";
		echo "<b>Line: $errline<br>";
		echo "<b>Type: $errcntxt<br><br>";
        echo "<b>Terminating Process....</b>";
		die();
		}
          ?>

I recommend you add that before the doctype.

now lets move onto actually testing it :)..

go onto a different part of your form and add this

Code:
<?php
       set_error_handler("errhandle") //tells PHP to use the function instead of default error handling.
       echo $oops
?>

save it as index.php or w/e you want as long as you keep .php

the above code will generate the error saying string doesnt exist! Obviously because you havent declared it to be anything.. Anyways this concludes my tut :) be creative and remember to use this, makes your code look professional
 
Runescape Gamblingrunescape gambling
Back
Top