note 52224 added to function.time
| From: | alex at osu1 dot php dot net | Date: | Mon, 25 Apr 2005 06:20:26 +0000 |
| Subject: | note 52224 added to function.time | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-88512@lists.php.net to get a copy of this message | ||
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.
----
Manual Page -- http://www.php.net/manual/en/function.time.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+52224
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+52224&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+52224&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+52224&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+52224&report=yes&reason=useless
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+52224&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+52224&report=yes
Search -- http://master.php.net/manage/user-notes.php