Jump to content

amount of time a page was viewed


coder330

Recommended Posts

hey guys...

 

i am writing a script for web page statistics.

one of the things that i have to show is the amount of time a page was viewed by a particular user.

any idea on how to get the amount of time?....

one way i can do that is start the counter when page is loaded and then send the value to the database once the page is  being redirected somewhere or it is being closed.

but how do i do that? how do i start the timer in php? how do i check for page load? page redirect? page close?

 

any help would be appreciated

 

thanks a lot.

Link to comment
Share on other sites

Well I'm not exactly a professional or anything but I don't think this can be done through PHP. PHP is all server side from what I last recall meaning that you couldn't do that.

 

On the other hand Jscript could do that I think.

 

Do correct me if I'm wrong though about PHP being client side only.

Link to comment
Share on other sites

Why not set a cookie or session?

 

Then have it check if the cookie/session exists, if it does.. write to a DB with the user's name OR cookie OR session or whatever you use and have it add +1 each time they view..

 

If they don't have the cookie/session, make one and add the user OR cookie OR session or whatever you use and set it to 1.

Link to comment
Share on other sites

thanks for the replies guys.

 

i think u misunderstood what i was asking.

i don't want to record how many times they visited ( i already have that)....I want to record for how long a user ABC was on a page XYZ the last time he/she visited that page. so for example 30 seconds, 5 minutes etc.

Link to comment
Share on other sites

thanks for the replies guys.

 

i think u misunderstood what i was asking.

i don't want to record how many times they visited ( i already have that)....I want to record for how long a user ABC was on a page XYZ the last time he/she visited that page. so for example 30 seconds, 5 minutes etc.

 

Oh, sorry..

 

You could uhh.. well,

 

Have it get the current time & current page, insert that into the DB, then for each page.. do that..

 

I'm not sure how you would do all this.. I guess fwrite() might work..

 

Have the script get the old url & old time, have it subtract the current time from the old one and have it show the old url, and insert the new info..

 

 

Imo, this would be VERY resource consuming and not very useful..

 

But since it's your decision, try my idea.

Link to comment
Share on other sites

Main Page:

 

<?php
blah blah

$pageview = $_SESSION['pageview'];
$time = round(time() - $pageview);
mysql_query("Do the insert");
?>

 

On all your files or some file that is included on all files:

 

<?php
include_once('blah page');

$_SESSION['pageview'] = time();

rest of content...

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.