0

I started the beginner with php. I need to get errors that append in my website I use below code for log errors into file but do not work. This has no any error.

<!DOCTYPE html>
<html>
<body>

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(E_ALL);

echo "My first PHP script!";
error_log( "Hello, errors!" );

?>
</body>
</html>  

What is problem?

3
  • what do you mean by "This has no any error." ? Where you expect it to be? Commented Sep 29, 2017 at 7:10
  • when reload page display on page My first PHP script! . with out any error Commented Sep 29, 2017 at 7:19
  • because there is no errors in this script. From docs, by default error_log() "sent to PHP's system logger, using the Operating System's system logging mechanism or a file, depending on what the error_log configuration directive is set to" Commented Sep 29, 2017 at 7:23

1 Answer 1

1

In the above code, you need to also instruct php to log errors. Add the following directive

$path =$_SERVER['DOCUMENT_ROOT'].'/path/file.txt';//tell php where to save your error logs

ini_set('log_errors',1);//logs errors 

ini_set('error_log',$path); //override php's default error log directory 
Sign up to request clarification or add additional context in comments.

5 Comments

I change my code such as this but do not write error into file <?php $path =$_SERVER['DOCUMENT_ROOT'].'/log.txt'; ini_set('display_errors',1); ini_set('log_errors',1); ini_set('error_log',$path); error_reporting(E_ALL); require('dd.ir'); ?>
Does the path variable exist??
@programmer138200 to display errors ini_set('display_startup_errors',1); ini_set('display_errors',1); error_reporting(E_ALL); is enough. You just don't see any errors because there is no such in your script. error_log() doesn't create an error, it just logs it.
The error log name is kinda confusing you. All it does is to log the string parameter to a file. Not specifically an error
@programmer138200 if you want to log errors into file with error_log() set second param "message_type" to 3 and third param file where you would like to write error_log("Error message", 3, 'my_errors.log');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.