I'm doing some testing as I'm new to PHP and Wordpress.
On refresh the following code runs functions.php
<?php $content = "some text here\n"; $fp = fopen($_SERVER['DOCUMENT_ROOT'] . "/wp-content/themes/zerif-lite-child/myText.txt","a"); fwrite($fp,$content); fclose($fp); ?>
Which writes to the .txt file multiple times! If I use "wb" it will write to the file only once, but I want this code to append the file, not overwrite it everytime.
I've tried using flock() but that produces the same result.
Why is it writing to this file multiple times when I append it?