Thread: Php timer and java combined
Results 1 to 4 of 4
Related
-
Need Java Help Please Forum: Javascript Forum
Replies: 0 -
Java Help Forum: Javascript Forum
Replies: 1 -
help with java Forum: Javascript Forum
Replies: 0 -
Any good Timer Scripts??? Forum: Website Scripts Forum
Replies: 3
-
03-07-2005, 03:50 PM #1
Php timer and java combined
Hope this is not falling on blind eyes, as I have posted in other forums but to no avail.
I have a small script (php class) that logs a user for the amount of time they are on a page (uses cookies) then displays the time clock in javascript.
Problem being is that form the script I can't see where to take the end time to a php varibale to enter it to a database!
The code is long so i shall @ present not post it.
Is there a way of logging a users time allocated to one page and diplay the time as it occurs (like a clock) then once the user has passed to another page teh time spent is taken to a variable.
The think i like about the script I have is that even if you refresh the page it still continues to count up (i.e the time still increases)
need some serious help if anyone can assist I would be eternily gratefull and I may even learn something.
-
03-07-2005, 04:57 PM #2
Hi welcome to the forums.
You could set the time spent variable into a cookie, on the next page PHP can read the cookie contents, and into database it goes. This sounds like what you are after.If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
03-07-2005, 05:16 PM #3
Php timer & javascript
Could be read from a cookie, which is what the class.php i have has already got with java script to display the time in mins and seconds.
Any ideas as to how.
Code shown below is what i think i have but i'm not to hot on java - php combination scripts plus it uses $that->Display[?????]
Need help to unravel it.
class time_online {
function time_online() {
$this -> userID = $_COOKIE["time_online_ID"]; // user's ID
$this -> userTT = $_COOKIE["time_online_TT"]; // user's total time on site
$this -> userST = $_COOKIE["time_online_ST"]; // time when user entered the site
$this -> userTO = $_COOKIE["time_online_TO"]; // time that the user has been online this sesion
$this -> displayID = 0; // ID used to generate diferent script in case of multiple call of display() function
if ($this -> userID != "") {
if ($this -> userST == "") {
$this -> userST = time();
setcookie("time_online_ST", $this -> userST);
}
$this -> userLPT = time() - $this -> userST - $this -> userTO;
$this -> userTT += $this -> userLPT;
setcookie("time_online_TT", $this -> userTT, time()+60*60);
$this -> userTO = time() - $this -> userST;
setcookie("time_online_TO", $this -> userTO);
$this -> userTO = time_online::normalizare($this -> userTO);
$this -> userTT = time_online::normalizare($this -> userTT);
}
if ($this -> userID == "") {
time_online::newID();
}
}
function newID() {
$this -> userID = md5(rand());
$this -> userST = time();
$this -> userTO = 0;
$this -> userTT = 0;
setcookie("time_online_ID", $this -> userID, time()+(60*60));
setcookie("time_online_ST", $this -> userST);
setcookie("time_online_TO", $this -> userTO);
setcookie("time_online_TT", $this -> userTT, time()+(60*60));
}
function normalizare($secunde) {
$minute = $secunde / 60;
$secunde = $secunde % 60;
$ore = $minute / 60;
$minute = $minute % 60;
$zile = $ore / 24;
$ore = $ore % 24;
return $timp = array("minutes" => $minute, "seconds" => $secunde);
}
function display_time($type){
$this -> displayID++;
if ($type == "current_page") {
$time_start_multiply = 0;
}
if ($type == "current_session") {
$time_start_multiply = $this -> userTO["minutes"]*60 + $this -> userTO["seconds"];
}
if ($type == "total_time") {
$time_start_multiply = $this -> userTT["minutes"]*60 + $this -> userTT["seconds"];
}
echo "
<script type=\"text/javascript\">
document.writeln(\"<span id=\\\"time_online" . $this -> displayID . "\\\"></span>\");
zi_inceput" . $this -> displayID . " = new Date();
ceas_start" . $this -> displayID . " = zi_inceput" . $this -> displayID . ".getTime();
function initStopwatch" . $this -> displayID . "() {
var timp_pe_pag" . $this -> displayID . " = new Date();
return((timp_pe_pag" . $this -> displayID . ".getTime()+(1000*$time_start_multiply) - ceas_start" . $this -> displayID . ")/1000);
}
function getSecs" . $this -> displayID . "() {
var tSecs" . $this -> displayID . " = Math.round(initStopwatch" . $this -> displayID . "());
var iSecs" . $this -> displayID . " = tSecs" . $this -> displayID . " % 60;
var iMins" . $this -> displayID . " = Math.round((tSecs" . $this -> displayID . "-30)/60);
var iHour" . $this -> displayID . " = Math.round((iMins" . $this -> displayID . "-30)/60);
var iMins" . $this -> displayID . " = iMins" . $this -> displayID . " % 60;
var iHour" . $this -> displayID . " = iHour" . $this -> displayID . " % 24;
var sSecs" . $this -> displayID . " = \"\" + ((iSecs" . $this -> displayID . " > 9) ? iSecs" . $this -> displayID . " : \"0\" + iSecs" . $this -> displayID . ");
var sMins" . $this -> displayID . " = \"\" + ((iMins" . $this -> displayID . " > 9) ? iMins" . $this -> displayID . " : \"0\" + iMins" . $this -> displayID . ");
var sHour" . $this -> displayID . " = \"\" + ((iHour" . $this -> displayID . " > 9) ? iHour" . $this -> displayID . " : \"0\" + iHour" . $this -> displayID . ");
document.getElementById('time_online" . $this -> displayID . "').innerHTML=iHour" .$this -> displayID . "+\":\"+sMins" . $this -> displayID . "+\":\"+sSecs" . $this -> displayID . ";
window.setTimeout('getSecs" . $this -> displayID . "()',1000);
}
window.setTimeout('getSecs" . $this -> displayID . "()',1000)
</script>
";
}
}
?>
Original author not responding and have tried for 1 week and several emails.
Need something as baove so that it displays time and logs it but then to enter total time into sql data.
Also when page refreshed it just accumulates the total time and does not restart fro zero.
Any one ideas.
Last of how to get the above code to display only mins and secs....days and housr not required!
Thanks
-
03-07-2005, 05:20 PM #4
Ah, so its not your work then? I'll be honest, I can point you in the right direction but I work as a web developer for a living and I cannot spend the (possibly) hours necessary to get that working.
If you don't know how to set a cookie with JavaScript (not Java, two different things) then try starting here:
http://www.w3schools.comIf one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum