2

I'm troing to change settings in php.ini throu php. My problem is that when there is an error, its not put in to the file error_log.txt, so what am I doing wrong?

This is my code:

// Settings for php.ini
ini_set("session.cookie_httponly", 1);
ini_set("session.cookie_secure", 1);
ini_set('display_errors', 'off');
error_reporting(0);

// errormeddelanden loggas i logs/errorlog.txt 
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/logs/error_log.txt');
Sanna Bergström
  • 85
  • 1
  • 1
  • 12

1 Answers1

6

You can use the function error_log().

A simple example from here would be like

ini_set("log_errors", 1);
ini_set("error_log", "/tmp/php-error.log");
error_log( "Hello, errors!" );

Then check the log file .you cold see like

tail -f /tmp/php-error.log
Community
  • 1
  • 1
Avinash Babu
  • 5,752
  • 2
  • 17
  • 24
  • Yes I have seen that, but I have a friend who only has this code and he gets the errors in to the log file. That is what I want to do. I cant find in his code that he uses error_log("error message"); I Want all errors on the site to go into that file, not just where I put error_log(); I Can't find what I'm doing different to him either.. – Sanna Bergström Nov 02 '14 at 15:44
  • It worked with changing ini_set('error_log', dirname(__FILE__) . '/logs/error_log.txt'); to ini_set("error_log", "/logs/error_log.txt"); I din't need to use the last code =). – Sanna Bergström Nov 02 '14 at 16:29
  • @SannaBergström wow ..am glad that it helped ...:) happy coding – Avinash Babu Nov 02 '14 at 16:37