How Get Time Spent on Webpage? Help, wont solve! over 5 hours :( !!
Hey everyone,
So I have a problem with javascript php and html integration... its a real pain in the a*s..
So first off I started to look for a way to save the amount of time a visitor spends on your webpage... Well, I found this tutorial after 20 minutes of looking: http://javascript.internet.com/time-...t-on-page.html
It was real nice, so I tried it. Worked like a charm, but then the hard part was to get its variables (that stored the total amount of time spent) to php, so I could record the data in my SQL Database...
But-- after an hour of trying to parse the php in js, and other way around and tried alot of crazy scripting things... , I realized you CAN'T send JS vars to PHP!!! So I was sooo confused, then I went to the html part of the tutorial. (You have to put a js script in the <head> and then put a onload and onunload interval statement in the <body>, following the tutorial)
So I thought, I'll change this js script to php... and it shouldve worked out fine, and I think it did. So I put the php version of tracking time spent in my index.htm (which can parse php). So then I tried calling functions in the <body onload = 'window.setInterval(<?php timeHere() ?>, 100)' onunload = <?php sayTime() ?>> I found out that if i put a test script it'll work...but the problem was, the onload statement. I tried calling the timeHere php function inside setInterval, but it just wouldnt work!
And I had no way of seeing that my time tracking php script worked, since "onunload" you go to a different page, and if i tried printing back data i wouldnt see it!
So I've been doing this crap for over 4-5 hours, and no luck.
So I am asking you, or someone, probably Musicman, or anyone else to help me create a way to record how much time a visitor spends time on a webpage of mine, and then pass the totalTimeSpent var to php.
Please Help!
Thanks