To be honest I've never done file locking in PHP, but the concept goes:
If User A opens log.txt and starts writing a string to it, but half way
through user B opens its and reads the file, User B will only get a half
written log.txt file. Then if B tries to do some writing it may end up
writing a corrupt file. (this is a general idea)

Anyway do a quick search for File Locking in the php manual (I've downloaded
the chm version and have it open alot!).
Also only last week was there a file locking discussion on this list, try
the archives (if they are any)

Andrew
----- Original Message -----
From: "Martin Clifford" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Wednesday, April 10, 2002 5:04 PM
Subject: Re: [PHP] Visitors Log Help


As I'm sort of new to this, can you expand on "file locking"?  As of now,
I'm running Apache on my home PC, but my host most likely will not allow me
access to it's apache log files.  That is the main reason I want to do this,
and also because I'm studying PHP and this looks like a good way to get a
handle on file permissions, file writing, reading, etc.  Thanks for
answering my question though! :)

Martin

>>> "Andrew Brampton" <[EMAIL PROTECTED]> 04/10/02 11:56AM >>>
Well that should write as soon as that php is requested...

BUT U might want to put some file locking in there to make sure 2 people
don't visit at the exact same time and corrupt your Vistor_Log.txt

BTW If are using apache a better option might be to look into the custom log
files it can make, I think it can do what you are trying to do in PHP

Andrew
----- Original Message -----
From: "Martin Clifford" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, April 10, 2002 4:36 PM
Subject: [PHP] Visitors Log Help


Hi all!

I am trying to build a Visitor_Log.txt file for my page, which will write
specific information about users that visit the page (time of day they
visited, browser they are using, operating system, etc) to a txt file on my
server.

My question is... how do I write these values to the file as soon as they
access the page?  I'm very comfortable with using JavaScript to get user
information, but I know that PHP also has built-in functions to get user
information as well... would I do something along the lines of...

<?

$TheFile = "log.txt";
$Open = fopen($TheFile, "a");
if($Open)
{
  fwrite($Open, "$HTTP_USER_AGENT\n");
  fclose($Open);
}

?>

If someone loaded a page with that in it, would it write to the file as soon
as it's accessed and interpreted, or would some action have to take place to
make it run?  I won't ask which PHP Variables can be used to get user
information, I can find that information in the Manual... any information as
to my questions would be wonderful!

Also, please CC me on responses since I'm on the digest!  Thank you in
advance!

Martin


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to