H I O X INDIA
FREE PHP Topics
 HOME  ||  Scripts  ||  Purchase  ||  Tutorials  ||  Images  ||  Tools  ||  Directories 
  :-)  Send Page   :-)   Feedback   :-)   Register   :-)   Links   :-)   Support   :-)   Bookmarks :-)  
 Forums   Hosting   Internet Stats   Easy Calculation   FUN Games 

PHP Topics
Introduction
Common Header
Random Number
Type
Form Variables
Date and Time
PHP Mysql Functions
File Handling
Error Handling
DB Size
PHP Mail
String Tokens
Running PHP from JS
Array To JS
Array to PHP
Encryption
Ask Your Doubts
Feedback





Error Handling in PHP


Topic

How to stop or block error, supress warning messages in the page?



Explanation

Error handling in php can be done very easily

Stop error reporting completely in PHP:
    To completely turn off error or warning messages on web pages you can use the function "error_reporting(0);"

For example, here we try to open a file that does not exit, we will get a warning as below
Code Used: e.g:
<?php
fopen('test.txt',r);
echo("test for error message");
?>

Result:
Warning: fopen(test.txt) [function.fopen]: failed to open stream: No such file or directory in /home/myscript/public_html/tutorials/php/error-handling/warningMessages.php on line 70
test for error message

Now with the same code we "set error reporting as 0" before calling other methods.
Code Used: e.g:
<?php
error_reporting(0);
fopen('test.txt',r);
echo("test for turning off warning message");
?>

Result: test for turning off warning message

So we have supressed or blocked all warning and error that are shown on web pages.

We can also use ini_set to turn off any error message being displayed. The property to be used is "display_errors". Note that using ini_set will overwrite all other related properties set using functions.
Code Used: e.g:
<?php
ini_set("display_errors",0);
.........
.........
.........
?>
To reset, use value as 1 instead of 0.

Next>> learn to block warnings on specific operations.




others


privacypolicy     licence     sitemap
(c) copyright, 2004 hioxindia.com