Solved

How can I add data to an existing log file?

Posted on 2013-05-21
3
229 Views
Last Modified: 2013-05-21
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

0
Comment
Question by:sasnaktiv
3 Comments
 
LVL 47

Accepted Solution

by:
dlethe earned 400 total points
ID: 39184993
the 'w' in the fopen means create a new file.  You want to use 'a' to append
0
 
LVL 7

Assisted Solution

by:Robert Saylor
Robert Saylor earned 100 total points
ID: 39185146
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
 
LVL 1

Author Closing Comment

by:sasnaktiv
ID: 39185180
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

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question