View Full Version : count up and log
janno123
10-25-2006, 10:48 AM
hello,
i am quite new in php, so please could you help me
how do you guys do so, that
1. time spent on page is shown to user on the same page (m:s)
2. the final times are recorded into a log file
djr33
10-25-2006, 12:37 PM
That's not complex with php, really. At least the math and storage isn't. (I'd say a database makes sense more than logs, but either could work, depending on what exactly you need.)
However, you can't tell how long someone was at a certain page.
For one, even if you did know they had that screen up for 20 minutes, that doesn't mean they didn't walk away to make a sandwich or something.
The only times that you will be able to know anything is when the user refreshes the page.
In theory, the time the page is loaded until the time another page is loaded represents the time on a page, but this doesn't take into account what the user was doing aside from that on his screen, multiple windows of your site (what if the old page is still open?), etc.
The best you could really hope for here is hits per page. That isn't very hard to code, and it's easy enough to define a hit, and to know when someone loads a page. "how long they viewed the page" is a lot more vague and there are a lot of reasons that would be hard to determine.
The only real way to determine time spend on a page would be to use AJAX. The javascript would track activity on the page (whether that window was active, and such, I suppose), and then use AJAX to call the PHP scripts behind the scenes.
That sounds complex to me. Not really sure how you'd do it.
And, you'd still have inaccuracies depending on how you saw the "time spent on a page".
janno123
10-25-2006, 12:54 PM
you do not even know for what i need the information, how does my page look like and how it is built up, but you argue so heavily
dude, i am sorry, but i got no help from your reply,
because i need just that what i described earlier
i asked just for code, if anyone could help me i am still asking
thank you
djr33
10-25-2006, 03:00 PM
Hey, I'm just trying to help.
If you give us/me more details, perhaps there's a better answer we can help with.
From what you said, you implied that you wanted a script that would apply to multiple pages in your website, for, what I assumed was, using to determine patterns in your visitors.
Doing that would be really hard.
If you need php/mysql info:
http://php-mysql-tutorial.com
It's an easy step by step tutorial.
It's not a "log" file, but it's php and a database. Databases are also easier if you ever need to retrieve or modify the information.
Files work out ok too.... fairly easy to do that.
fopen() will open a file for editing,
fwrite() will change it's contents,
and fclose() completes the process (memory and security).
Info on these is available on php.net
If you give us more info we can give you more specific info as well.
As for a script, I don't know of one and I don't have the time to write that myself, especially since I don't know what you're after, exactly.
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.