note 19910 deleted from function.fwrite by philip
| From: | philip@php.net | Date: | Sat, 19 Oct 2002 17:36:57 +0000 |
| Subject: | note 19910 deleted from function.fwrite by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-38302@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);
}
?>