tags:

views:

65

answers:

3

What do php geeks, professionals, and all others us to log their flat files.

Are there functions that can just log one .php page?

Can the logging in php be controlled?

On a side-note, anyone used this for logging? [http://www.monperrus.net/martin/phpmodlog%5D%5B1%5D

Apparently my first question was not clear...

A: 

What do you mean by has finished playing? How do you define that. Without JS there is no posibility to know when a user leaves the page.

But you would have to elaborate on what you pricesely mean by those events to give you advice.

The most accurate you can be is logging everytime a user hits a page. And then when a certain time is passed without activity, the user stopped playing.

Ikke
Closes browser window.
Newb
There is like no function that just logs everything?
Newb
For a given php page?
Newb
No. You should take a deeper look into SESSIONs, using them provides you with what you need to do this logging yourself.
halfdan
@halfdan: Sessions aren't going to help because you don't know when a session is timed out.
Ikke
@halfdan: I can log with sessions?
Newb
A: 

If you are on PHP5 then you could look at using sqlite, which stores information in a text file.

Might take you some time to work it out but you could also look at using the library at PEAR::Log which provides a very simple logging mechanism.

http://pear.php.net/package/Log

Cups
Reading about it...
Newb
Newblet head aches...
Newb
This is only the logging part. But he still doesn't know how he gets the data.
Ikke
+2  A: 

You could create a function that uses fwrite to write your events to a log file.

eg:

function logEvent($message) {
    if ($message != '') {
        // Add a timestamp to the start of the $message
        $message = date("Y/m/d H:i:s").': '.$message;
        $fp = fopen('/path/to/log.txt', 'a');
        fwrite($fp, $message."\n");
        fclose($fp);
    }
}

You should also add checks that the file is writeable, which you can find code for on the fwrite page.

For each of the events that you mention, you can then do:

// Log that user has started playing
logEvent('User '.$user.' has started playing Battleships.');

Expand it to include/do whatever you want.

Edit: You've edited your question, but I'll leave my answer here because you may find it useful. As others have mentioned though, you really can't reliably tell when someone has closed the browser window. Also changed to append rather than override.

Blair McMillan
Thanks, I figure I will make this work with the given function and other ideas, I had before posting.Sorry for editing the question, I wanted to make sure the question was not ambiguous.
Newb
Not a problem. The edit information was more there for other people who view the question after you had edited it and see my answer that doesn't seem particularly relevant.Good, I was hoping you would add more things to it. Glad it got you started.
Blair McMillan