note 19910 added to function.fwrite
| From: | sjohnson at fuzzygroup dot com | Date: | Thu, 14 Mar 2002 19:35:38 +0000 |
| Subject: | note 19910 added to function.fwrite | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-27798@lists.php.net to get a copy of this message | ||
Here is a very simple, yet complete example of logging CGI variables to a text file. It tests if
the text file exists and creates it if it doesn't. Useful for simple variable journally when
table structures are _ahem_ flexible.
<?php
// *********************
//logging routines
//file based logging just to be safe in
//case DB stuff doesn't work for some silly reason:
//expected CGI vars for testing.
//uncomment them for trying it out
//$title="Job - CTO";
//$user="fuzzygroup";
//$password="taft";
//$url="http://www.aaa.com/jobs/cto.html";
$logfile = "jobwenchaddlog.log";
if (file_exists($logfile)) {
//print "The file exists!";
// open file for append to end and write
$fp = fopen ("$logfile", "aw");
// write the params as name value pairs
fputs ($fp, "^^url=$url^^, ^^title=$title^^, ^^user=$user^^, ^^password=$password^^\n");
// close the file
fclose($fp);
}
else {
//open file for write
$fp = fopen ("$logfile", "w");
//print "The file does not exist";
// write the params as name value pairs
fputs ($fp, "^^url=$url^^, ^^title=$title^^, ^^user=$user^^, ^^password=$password^^\n");
// close the file
fclose($fp);
}
?>
--
http://www.php.net/manual/en/function.fwrite.php
http://master.php.net/manage/user-notes.php?action=edit+19910
http://master.php.net/manage/user-notes.php?action=delete+19910
http://master.php.net/manage/user-notes.php?action=reject+19910