note 46769 deleted from function.time by sean
| From: | sean@php.net | Date: | Sat, 23 Oct 2004 02:46:00 +0000 |
| Subject: | note 46769 deleted from function.time by sean | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-78970@lists.php.net to get a copy of this message | ||
Note Submitter: evildictaitor at hotmail dot com
----
IMPORTANT!
The PHP function <? time() ?> returns the number of SECONDS since the Epoch (1st Jan 1970).
The JAVASCRIPT function: Date()* returns the number of MILLISECONDS since the Epoch.
*code litterally Number(new Date()) as new Date() returns a string.
In order to have a dynamic server time through javascript, rather than the dynamic time of the
client computer, use the code:
<html>
<head>
<title>Clock</title>
<script>
serverUNIXtime=<?= time()*1000 ?>;
usertime = new Date();
useroffset = serverUNIXtime - usertime;
function showtime(){
d=new Date(Number(new Date())+useroffset);
document.forms['timeupdate'].elements['timer'].value=d;
window.status=useroffset;
}
</script>
</head>
<body onload="setInterval('showtime()',250)">
<!-- Your code here -->
<form name="timeupdate">
<input name="timer" style="background-color:transparent;border:0px"/>
</form>
<!-- Your code here -->
</body>
</html>
PS. The code for useroffsetted time is also useful for trying to do more clever ways of identifying
"hackers" to your webpages, since many use a proxy, but few change their actual system
time to compensate for where their proxy is based.
----
Reason: useless example