Manual of PHP

 
 
 

Web map

 
rim   rim
arrowReady frontarrow of Codes PHParrow to Create an errors log

 

To create an errors log To print E-mail
Like creating a file that stores the errors that have taken place during the execution of a program, to add an errors log to our page.


An errors log, will allow us to control when there is
produced an error to correct it and to prevent from repeating itself in
future.

To create a log, we will open the file in way "for" (it registers to

end) and we will write the error indicating the date, to simplify
we can include work everything in a function:

<? php
function error ($numero, $texto) {
$ddf = fopen ('error.log', 'to');
fwrite ($ddf, "[".date ("r")."] Error $numero: $texto\r\n");
fclose ($ddf);
}
?>


As soon as it was declared the function, tansolo we will have to call it of
following way when an error takes place so that he keeps in
error.log:

<? php
//If the cookie meeting does not exist
if (! isset ($_COOKIE ['meeting'])) {
//We keep an error
error ('001', 'the meeting cookie does not exist');
}
?>


This way, whenever a user enters this page without
cookie meeting, a new line is stored in the file indicating:

[date] Error 001: The meeting cookie does not exist

We are going to see now as we can improve this so that in addition to being able to record the errors that we define in our place, it stores to us the errors produced during the execution of the script php.

We will obtain this indicating the interpreter Zend who should call to
function error () whenever the code PHP contains an error with
function set_error_handler:

<? php
set_error_handler ('error');
?>

Then, we have left the finished code of the following way:

<? php
function error ($numero, $texto) {
$ddf = fopen ('error.log', 'to');
fwrite ($ddf, "[".date ("r")."] Error $numero:$texto\r\n");
fclose ($ddf);
}
set_error_handler ('error');
?>

And this way we give for our script finished to generate one
log of personal errors and of PHP.

Eloi of St Martin
http://www.programacionweb.net/articulos/articulo/?num=264

 

 
Front
Chapters of the Manual of PHP
Introduction to PHP
Variables
My First Script PHP
Operators in PHP
Structures of Control
Functions in PHP
Code inclusion
Counterfoils (array)
Chains of Characters
Classes
Dates
Entry and Exit
Operations with Files
The language SQL and PHP
Connection with MySQL
Meetings
Forms with PHP
To practise in line
List of practices in line
FAQ
Frequent questions
Codes PHP
List of Codes PHP
Forums
Forums PHP
Other Manuals
Manuals of other languages
 
   
 
 
MySpaceScripts.info - Sitemap - Contact us - Sitemap - Contact us - Sitemap - Contact us

Li-Ion Battery for IBM , speed test , bílé víno , Panasonic , car.auto-moto-blog.co.uk , posizionamento Google , Mehrgenerationenhaus