Solved

How can I add data to an existing log file?

Posted on 2013-05-21
3
233 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Title # Comments Views Activity
How do I remove "" from json_encode 5 35
Building a glossary into your website 9 60
JSON decode 5 46
No option to replace table data in phpmyadmin using CSV file import 11 52
Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
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.

759 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