note 46769 added to function.time
| From: | evildictaitor at hotmail dot com | Date: | Fri, 22 Oct 2004 15:44:26 +0000 |
| Subject: | note 46769 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-78950@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+46769
Delete -- http://master.php.net/manage/user-notes.php?action=delete+46769&report=yes
Reason: bad code -- http://master.php.net/manage/user-notes.php?action=delete+46769&report=yes&reason=bad+code
Reason: spam -- http://master.php.net/manage/user-notes.php?action=delete+46769&report=yes&reason=spam
Reason: useless example -- http://master.php.net/manage/user-notes.php?action=delete+46769&report=yes&reason=useless+example
Reason: contains commercial links -- http://master.php.net/manage/user-notes.php?action=delete+46769&report=yes&reason=contains+commercial+links
Reason: useless note -- http://master.php.net/manage/user-notes.php?action=delete+46769&report=yes&reason=useless+note
Reject -- http://master.php.net/manage/user-notes.php?action=reject+46769&report=yes
Search -- http://master.php.net/manage/user-notes.php