-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path34.php
63 lines (53 loc) · 1.4 KB
/
34.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
session_start();
unset($_SESSION['ts']);
$timestamp = time();
$diff = 60; //<-Time of countdown in seconds. ie. 3600 = 1 hr. or 86400 = 1 day.
//MODIFICATION BELOW THIS LINE IS NOT REQUIRED.
$hld_diff = $diff;
if(isset($_SESSION['ts'])) {
$slice = ($timestamp - $_SESSION['ts']);
$diff = $diff - $slice;
}
if(!isset($_SESSION['ts']) || $diff > $hld_diff || $diff < 0) {
$diff = $hld_diff;
$_SESSION['ts'] = $timestamp;
}
//Below is demonstration of output. Seconds could be passed to Javascript.
$diff; //$diff holds seconds less than 3600 (1 hour);
$hours = floor($diff / 3600) . ' : ';
$diff = $diff % 3600;
$minutes = floor($diff / 60) . ' : ';
$diff = $diff % 60;
$seconds = $diff;
?>
<div id="strclock">Clock Here!</div>
<script type="text/javascript">
var hour = <?php echo floor($hours); ?>;
var min = <?php echo floor($minutes); ?>;
var sec = <?php echo floor($seconds); ?>
function countdown() {
if(sec <= 0 && min > 0) {
sec = 59;
min -= 1;
}
else if(min <= 0 && sec <= 0) {
min = 0;
sec = 0;
}
else {
sec -= 1;
}
if(min <= 0 && hour > 0) {
min = 59;
hour -= 1;
}
var pat = /^[0-9]{1}$/;
sec = (pat.test(sec) == true) ? '0'+sec : sec;
min = (pat.test(min) == true) ? '0'+min : min;
hour = (pat.test(hour) == true) ? '0'+hour : hour;
document.getElementById('strclock').innerHTML = hour+":"+min+":"+sec;
setTimeout("countdown()",1000);
}
countdown();
</script>