Page session in php, I want to store the time spent by the user on a particular page...?
<p>Can any one help in storing the time spent by user on a particular page...
This is what I did...
It seams to work but i don't know my my php page is unable to get the data and store in database...
individually while I am calling StoreTime.php?time=23 it is getting the time value and storing the data...</p>

<pre><code>&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;
        Page time
    &lt;/title&gt;
&lt;/head&gt;
&lt;script type="text/javascript"&gt;

    var time=1;

    function timeHere() 
    {
        time = time + 1;
        finalTime = time / 10;
        document.title = finalTime;
    }

    function sayTime() 
    {
        finalTime = time / 10;
        showTime(finalTime);
        alert("U are in this page for " +finalTime+" Sec");
    }


    function showTime(finalTime)
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
        {
            // code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {
            // code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200)
            {
                document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
            }
        }
        xmlhttp.open("GET","StoreTime.php?time=" +finalTime,true);
        xmlhttp.send();
    }

    function sendTimeSpent(finalTime)
    {
        if (window.XMLHttpRequest)
        {
            xmlhttp=new XMLHttpRequest();
        }
        else
        {
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.open("GET","/Test/Timer/StoreTime.php?time="+finalTime,true);
        xmlhttp.send(null);
    }
&lt;/script&gt;   
&lt;body onload='window.setInterval("timeHere()", 100)' onunload="sayTime()"&gt;
    Close the page to see the time spent on this page...
    &lt;div id='myDiv'&gt;&lt;/div&gt;
&lt;/body&gt;
</code></pre>

<p></p>
