Logging Form post

This feels pretty beginner question, but I’m trying to log a form upload and I really can’t get php code to fix it.

This is essentially my submission HTML form

<form method="post" action="./Registrator.php" id="register">
Username: <input type="text" name="username" id="username" size="25" value="" title="Username" />
	<fieldset class="submit-buttons">
		<input type="reset" value="Reset" name="reset" />&nbsp;
		<input type="submit" value="Submit" name="submit" />
	</fieldset>
</form>

But seriously, what php do I need in Registrator.php to simply write the entry to a log file log.txt, a new line at a time?
I’ve been looking for hours online, I must be idiotic, but this is getting silly, so I ask for your help.

Thanks for reading and for any help you have to offer.

[php]

<?php date_default_timezone_set('US/Eastern'); $fulldate = date("D, d M Y - h:i:s a"); $file = 'logs.txt'; // open file append to file $fh = fopen($file, 'a') or die('Could not open file!'); // write to file fwrite($fh, "Username: ".$_POST['username']." On $fulldate\n") or die('Could not write to file'); // close file fclose($fh); ?>

[/php]

if for instance you enter on the textbox wilson382,this should append to a file something like this:

Username: wilson382 On Fri, 10 Aug 2012 - 03:34:15 pm

Also, some people log entries into a database. You said “I’m trying to log a form upload”.
If you want to log any item, you can do it as Wilson382 said. The logs can contain just about
anything you wish. I have one high-end site that I maintain that logs log-in’s, log-out’s, uploads
and profile changes. I use a database which can be searched to remove older data. This is nice
to keep archives on some items and delete older ones. (You really don’t need a million log-in records
just maybe the last year’s worth… as an example.)

Let us know if you have further questions or if you solve it… Good luck.

Sponsor our Newsletter | Privacy Policy | Terms of Service