The script writes the data correctly.
Most likely, they are displayed incorrectly. For line wraps to be like in a file, you need to wrap the output of your logs in the <pre> .
Update: now I understand what your problem is. You are trying to open a file in a browser by accessing it directly and not seeing the line breaks you have placed. All this happens because you save data to a file with *.php extension.
Change the extension of your file, for example, to .txt and the problem will be solved.
After that, update your code that writes data to a file in order to save data to a file with a new extension:
<? $ip=getenv("REMOTE_ADDR"); $date=date("d MY, H:i:s"); $agent=getenv("HTTP_USER_AGENT"); $str=(" Data - $date Ip - $ip Browser - $agent -------"); $log = fopen("base.txt","a+"); // Изменения в этой строчке fwrite($log,"\n $str \n" ); fclose($log); ?>
Accordingly, now to view the logs you will need to refer to the base.txt file.