coder330 Posted March 15, 2009 Share Posted March 15, 2009 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. Quote Link to comment Share on other sites More sharing options...
PugJr Posted March 15, 2009 Share Posted March 15, 2009 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. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted March 15, 2009 Share Posted March 15, 2009 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. Quote Link to comment Share on other sites More sharing options...
coder330 Posted March 15, 2009 Author Share Posted March 15, 2009 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. Quote Link to comment Share on other sites More sharing options...
Cory94bailly Posted March 15, 2009 Share Posted March 15, 2009 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. Quote Link to comment Share on other sites More sharing options...
coder330 Posted March 15, 2009 Author Share Posted March 15, 2009 haha thanks for all the help. i dont think its doable in an easy way...oh well:( Quote Link to comment Share on other sites More sharing options...
killah Posted March 15, 2009 Share Posted March 15, 2009 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... ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.