note 42709 added to features.remote-files
| From: | garthatpctechsourcedotcom at rn2 dot php dot net | Date: | Wed, 26 May 2004 19:52:37 +0000 |
| Subject: | note 42709 added to features.remote-files | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-70143@lists.php.net to get a copy of this message | ||
Can't use fopen() for system loggging/general logging?
No way! see below.
Take a close look at the fopen() documentation. only if you use the argument "x" or
"x+" will it fail if the file already exists! Like the unix fopen, it will actually just
open the file for reading "r", writing "w" or both "r+",
"w+". Speaking of system logging...
here's a simple way to create a log of... well, whatever you want. This particular one just
records the visitor's time and ip addy.
<?php
$accesstime = date("Y/m/d H:i:s");
$visitorinfo = "[$accesstime] $_ENV[REMOTE_ADDR] \n";
$file = "visits.log";
fopen($file, "a");
fwrite($file, $visitorinfo );
fclose($file);
?>
"a" is for Append. It puts the pointer at the end of the file, thus creating a
chronological log starting from the first access and ending with the last.
What remains for you to do is determine when/how it decides to limit the file size, because this
will swallow up file blocks quickly for a heavily visited site.
Obviously this log is insecure on its own, but if you can't reconfigure the system's (that
your website is on) system log, and don't want to clutter it with your logging stuff, this
might be a good idea.
Cheers.
----
Manual Page -- http://www.php.net/manual/en/features.remote-files.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+42709
Delete -- http://master.php.net/manage/user-notes.php?action=delete+42709&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+42709&report=yes
Search -- http://master.php.net/manage/user-notes.php