yoda69 Posted April 13, 2010 Share Posted April 13, 2010 Is there a way to measure how long a user spent on a page using php? Or better, is there a way to measure how long it took a user to confirm a form (click a submit button or a link) once the form element was loaded? Thanks Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/ Share on other sites More sharing options...
ChemicalBliss Posted April 13, 2010 Share Posted April 13, 2010 There is no active connection between the server and the client with php. All you can do is Guesstimate - Set a timestamp for the current page the user requested, once the user changes/;requests a new page, reset the timer. Though once the user leaves the last page would be a long time so the last page is the most inaccurate. Even though you cant really tell how long someone is looking at a page (which is more releveant than being on a page and not looking). Basically you can get estimatesd but never a relevant exact accurate number. -CB- Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1040920 Share on other sites More sharing options...
yoda69 Posted April 13, 2010 Author Share Posted April 13, 2010 Okay, I guess then that the only way of doing what I want is using javascript? Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041027 Share on other sites More sharing options...
Ken2k7 Posted April 13, 2010 Share Posted April 13, 2010 Yeah, but it's not really reliable to use JavaScript. There are many things the user can do that will mess with data. Such as closing the window. Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041029 Share on other sites More sharing options...
ChemicalBliss Posted April 13, 2010 Share Posted April 13, 2010 And as i said, unless you have some extremely sophisticated webcam recognition software that could magically tell between different people, you just cant do it accurately. You will only get a guide, and the easiest guide is an average of time spent on all your pages. By tall ying up the times between page requests. -CB- Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041055 Share on other sites More sharing options...
aeroswat Posted April 13, 2010 Share Posted April 13, 2010 You could save the current time on the form page and then save the time when submitted and compare the two? Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041060 Share on other sites More sharing options...
Ken2k7 Posted April 13, 2010 Share Posted April 13, 2010 You could save the current time on the form page and then save the time when submitted and compare the two? And what if someone navigates away from the page and then return a few days later? Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041073 Share on other sites More sharing options...
aeroswat Posted April 13, 2010 Share Posted April 13, 2010 You could save the current time on the form page and then save the time when submitted and compare the two? And what if someone navigates away from the page and then return a few days later? Well his actual question was to see when a submit button was pressed after the page had been loaded. So a timestamp easily takes care of this problem with no issues. 1) Page loads 2) Timestamp is set 3) User clicks submit button 4) Submission code executes + 2nd timestamp is set fail safe Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041074 Share on other sites More sharing options...
yoda69 Posted April 13, 2010 Author Share Posted April 13, 2010 Yeah, basically its exactly what I need. I'm running a psychological experiment so I need to find out how long a certain page with a specific psychological question was viewed and answered. The user is not supposed to go back to that page. Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041121 Share on other sites More sharing options...
yoda69 Posted April 13, 2010 Author Share Posted April 13, 2010 What would be the actual syntax of timestamp ? Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041123 Share on other sites More sharing options...
yoda69 Posted April 13, 2010 Author Share Posted April 13, 2010 Okay. Got it First page: $time1 = time() second page: $time2 = time() $totalTime = $time1 - $time2 Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041134 Share on other sites More sharing options...
ChemicalBliss Posted April 13, 2010 Share Posted April 13, 2010 Yeah if you want to be really accurate use microtime() (it gives an array, just add both together.) If it is a test, then it wil be by someone willing/interested - So you can assume most will follow your rules (not going back for ex.). But, they will cheat etc, but if its like an iq test it doesnt matter if they cheat, cuz if they arent honest it will be false anyway. I reccommend testing it yourself, and doing everything you can think of to it, then put it up on the website security check forum (or w/e), get people to tell you what they find is wrong. o btw - it helps if the topic is marked as solved. Cheers. -cb- Link to comment https://forums.phpfreaks.com/topic/198373-measuring-time-on-a-page/#findComment-1041173 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.