[wplug] PHP help

Bill Moran wmoran at potentialtech.com
Wed Jan 4 20:11:05 EST 2006


On Wed, 4 Jan 2006 19:37:52 -0500
Tom Rhodes <trhodes at FreeBSD.org> wrote:

> On Wed, 4 Jan 2006 18:19:05 -0500
> Zach <netrek at gmail.com> wrote:
> 
> > I would like the following script to save stats to a file called
> > "stats.txt" in the CWD (Linux).
> > Anyone know how modify the code to do this:

I'm not 100% sure I understand your exact intent, by you may get some
effeciency by using serialize() and unserialize() to marshall the data
for storage.  For example:

$h = fopen('somefile.txt', 'w');
fwrite($h, serialize($_SERVER));
fclose($h);

You can later retrieve the values by using fopen() to read the file into
a variable, then unserialize() that into the original array.  (Note that
you can serialize/unserialize class objects, which is pretty cool ...)

The serialized data format is _sorta_ human readible, although not
particularly eye-friendly.  If it's not what you want, you can just
fwrite() the text string you want to write to the file.  Don't forget
line breaks.

If you're trying to create a logfile thing, use fopen with 'a' for 
append.  But if you want logfile-like functionality, you'll probably
be happier using the syslog() functions in PHP to send messages through
the system logger.

Hope one of these ideas works for you.

> By using the fopen() function call.  I can't remember,
> it's been so long since I touched PHP.  Something like:
> 
> fopen(stats.txt, "w")
> 
> Or some crap.  It's not much, but perhaps a starting point?
> 
> > 
> > <?php
> > echo "<table border=\"1\">";
> > 
> > echo "<tr><td>Date/Time</td><td>".date('Y-m-d H:i:s')."</td></tr>";
> > 
> > foreach($_SERVER as $key=>$value) {
> >        echo "<tr><td>".$key."</td><td>".$value."</td></tr>";
> > }
> > 
> > echo "</table>";
> > ?>


-- 
Bill Moran
Potential Technologies
http://www.potentialtech.com


More information about the wplug mailing list