How to use the PHP error log function
The error_log function is widely used in PHP to send error messages to the web server.
The syntax is:
error_log(message, type, destination, headers)
messageis the user-defined error message.typespecifies where the error should go.
0 - By default, the message is sent to the PHP system logger.
1- Email is sent to thedestinationspecified. This parameter also makes use ofheadersto add additional information.
3- The message is attached to the file specified in the destination.
4- The message id directly sent to the logging handler.SAPI An API provided by the webserver to help extend server capabilities. destinationspecifies the addressee or the file name depending on thetype.headersspecify the from, cc, bcc if thetypeis set to .
Only message is required, the rest are optional fields.
The function returns true or false depending upon the success or failure of the log.
Remember: It is not binary safe and; therefore, a null character will truncate the message.
Code
The following code gives an example of how failed login attempts can be logged in a file:
<?php// Notify the system of multiple invalid login attemptserror_log("Multiple failed attempts for user", 3, "/var/tmp/system_errors.log");?>
This function can be used to send emails to other users, use default settings, or send the error logs to the SAPI logging handler depending upon the type selected by the user.
Free Resources
Copyright ©2026 Educative, Inc. All rights reserved