RE: [PHP] createing a log file
| From: | John W. Holmes | Date: | Sat, 19 Apr 2003 20:00:53 +0000 |
| Subject: | RE: [PHP] createing a log file | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144500@lists.php.net to get a copy of this message | ||
> have a log file im trying to write (simple one right now ) but heres
the
> code for it:
> $date=date("M/d/Y");
> $log=fopen("login.log", "a");
> fwrite($log, "[$date] $user logged in\n");
> fclose($log);
> include("main.php");
> }
> ?>
>
> heres the output for it after i put my username/password in the login
> screen
> and log in i get this in the log file:
>
> [Apr/19/2003] root logged in
> [Apr/19/2003] logged in
>
> any idea how to fix the line with no username in it? expecially when i
> dont
> have code for it anywhere...
Well, the easy fix would be to check $user for a value before you write
it.
Also, you may want to look at the error_log() function to do what you're
doing and provide extra functionality.
http://www.php.net/manual/en/function.error-log.php
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/