How can I add data to an existing log file?

Hi Guys,
The following code does a good job of placing the $stringData into the $log_file.
But it replaces any existing data that's already in the $log_file.

How should I write this so that it will add the $stringData to the existing content instead of replacing it?

Thanks in advance for the help,
Sas
<?php
$email=$_REQUEST['Visitors_eMail'];
$Today = date("F m, Y",time());

$log_file = "../directory_1/VisitorLog";
$fh = fopen($log_file, 'w') or die("can't open file");

$stringData = "
Date: $Today
E-mail: $email \n";

fwrite($fh, $stringData);
fclose($fh);
?>

Open in new window

LVL 1
sasnaktivAsked:
Who is Participating?
 
DavidConnect With a Mentor PresidentCommented:
the 'w' in the fopen means create a new file.  You want to use 'a' to append
0
 
Robert SaylorConnect With a Mentor Senior DeveloperCommented:
The 'a' should do it as mentioned above.

Here are some more options depending on how you want to handle the file.

Note: This is from php's site.

http://php.net/manual/en/function.fopen.php
0
 
sasnaktivAuthor Commented:
Thanks Guys,
That was very helpful, and as I suspected a simple solution.
The extra info from rsaylor should be helpful too.
Enjoy your day,
Sas
0
All Courses

From novice to tech pro — start learning today.