Solved

How can I add data to an existing log file?

Posted on 2013-05-21
3
231 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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 create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

735 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