Hi guys!
I would like to know the total time someone spent on my website by saving it into a textfile. Is this possible? I've used this code so far. When the form is filled in, I want to know the time spent on filling in the form and submitting it(real code is longer).
This code is not good because it just displays the time when a user visits the last screen(I understand why). But If I declare it above the if statement, it returns a totaltime of 0:0:0.(I also understand why, I just don't know any solution to the problem.) Is there any solution without using MySql?
<?php
$name = $_GET['sid'];
if(!isSet($_GET['sid'])){
$Hin = date("H");
$Min = date("i");
$Sin = date("s");
$timein = $Hin.":".$Min.":".$Sin ;
$date = date("D d M Y");
$fp = fopen("formdata.txt", "a");
$savestring = $name . ", ".$date. ", " . $timein . "\n";
fwrite($fp, $savestring);
fclose($fp);
echo '<form name="input" action="./StudentAnswers.php" method="GET">';
echo '<input type="text" name="sid"/>';
echo '<input type="submit" value="Submit">';
}
else{
echo "End of exercices";
$Hout = date("H");
$Htot = $Hout - $Hin;
$Mout = date("i");
$Mtot = $Mout - $Min;
$Sout = date("s");
$Stot = $Sout - $Sin;
$TotalTime = $Htot.":".$Mtot.":".$Stot ;
$fp = fopen("formdata.txt", "a");
$savestring = $name . ", total time: " . $TotalTime. "\n";
fwrite($fp, $savestring);
fclose($fp);
}
?>