note 52224 deleted from function.time by betz
| From: | betz@php.net | Date: | Mon, 25 Apr 2005 11:11:22 +0000 |
| Subject: | note 52224 deleted from function.time by betz | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-88522@lists.php.net to get a copy of this message | ||
Note Submitter: alex
----
After trying for quite some time to manipulate PHP functions to add a timestamp to user submitted
comments/posts that would be accurate with the CLIENT'S current time, I found the following
workaround that still uses some PHP but solves a problem that many of you might be running in to:
<form action="test.php" onsubmit="addTime()">
<input type="hidden" name="time" id="time">
<input type="submit" value="Submit" name="submit">
</form>
<script language="JavaScript">
function addTime() {
var d = new Date();
document.getElementById('time').value=Math.floor(d.getTime()/1000);
}
</script>
the PHP file pointed to in the action property of the form can then grab the user's time of
submission from the $_POST (or just $time).
If you're wondering about the d.getTime()/1000 it is because the getTime javascript method
returns timestamp in milliseconds instead of seconds.