【发布时间】:2015-04-09 07:45:26
【问题描述】:
我想获取 $_POST 时间和提交后页面内生成的时间之间的差异。
因为我想做一个 if 语句,如果两次之间的差异小于 5 秒,那么...否则...
使用 php date("H:i:s); 函数是否正确?
生成时间
<?php date = date("H:i:s"); ?>
隐藏表单域中的回显时间
<input name="tstmp" type="hidden" value="<?php echo $date; ?>"/>
然后在用户提交表单后被定向到的页面中。
//could the problem be this is a string within the $_POST
$timestart = $_POST['tstmp'];
$timeend = date("H:i:s");
//can this only be used with timestamp?
$interval = $timestart->diff($timeend);
【问题讨论】:
-
//can this only be used with timestamp?不...但是,由于diff()是DateTime类的方法,它只能从该类的对象中调用。date()函数的结果是一个字符串!!! -
为什么不首先将 unix 时间戳值放入表单中? (如果您只使用
H:i:s,我可以在明天或下周的这个时候再次发送相同的表格,这可能不是您想要的......)
标签: php validation datetime post spam-prevention