define('PATH_LOG', 'path.log'); include 'inc/log.inc.php'; //log.inc.php $dt = time(); $page = $_SERVER['REQUEST_URI']; $ref = $_SERVER['HTTP_REFERER']; $ref = pathinfo($ref, PATHINFO_BASENAME); $path = "$dt|$page|$ref\n"; file_put_contents('./log/'.PATH_LOG, $path, FILE_APPEND); //view-log.inc.php if(file_exists('log/'.PATH_LOG)){ $log = file('log/'.PATH_LOG); if(is_array($log)){ echo '<ol>'; foreach($log as $line){ list($dt, $page, $ref) = explode('|', $line); $dt = date('dmY H:i:s', $dt); echo <<<LINE <li> $dt: $ref --> $page </li> LINE } echo '</ol>'; } } 

I get the error:

Warning: file_put_contents (log / path.log): Failure to open stream: No file or directory in W: \ domains \ mysite.local2 \ inc \ log.inc.php on line 8

I can not understand why?

  • Well, based on the error, you can not see the file or directory. You can try to change to ('./log/'.PATH_LOG, $path, FILE_APPEND) - LamerXaKer
  • still does not give. maybe the problem is in openserver? - dron4ik
  • Can you add the code in the form of text and not a picture? - Saidolim
  • changed from picture to text - dron4ik
  • You do not have a log directory. PHP does not create default directories when creating files. - etki

1 answer 1

Open Server has nothing to do with it. You are accessing a $ref\n variable that is not defined. You have $ref , but $ref\n not! To put a line break, you must specify \n in quotes and concatenate it with the rest of the line.

Instead:

$path = "$dt|$page|$ref\n";

Try this:

$path = (string)($dt.' | '.$page.' | '.$ref. "\n");

Is this from the textbook of Igor Borisov? I can throw off the ready decision through a cycle for .