我有一些代码可以向我的数据库提交一些值,我希望客人能够每 24 小时提交一次。我更想知道如何使用 cookie 来做到这一点,因为 IP 限制会限制 NAT 用户。
它必须在一个单独的 PHP 文件中吗?
这是我当前的代码:
<?php
$con=mysqli_connect("host","user","pass","db_name");
// Check connection
if (mysqli_connect_errno ())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//post result to db
$result_set = mysqli_query($con,"SELECT points FROM total WHERE id = 1");
$row = mysqli_fetch_assoc($result_set);
$old_total = $row['points'];
$new_total = $old_total + $_REQUEST['total'];
mysqli_query($con,"UPDATE total SET points = $new_total WHERE id = 1");
mysqli_close($con);
?>