简体   繁体   English

PHP&MYSQL-每天限制数据库中的用户?

[英]PHP & MYSQL - Limit user in database per day?

Ok, so I'm struggling here. 好吧,所以我在这里苦苦挣扎。 So I'm setting up a little project, where a user can filter & search for whatever he wants . 因此,我正在建立一个小项目,用户可以在其中过滤和搜索所需的内容。 EG Searches hello for 10 searches (10 results to be shown) EG搜索打招呼10次(将显示10个结果)

So after all of that I need to add the INT that he's searched (results fetched) and + it with the other current value that's under his primary ID for that user via INSERT. 因此,所有这些之后,我需要添加他搜索过的INT(获取的结果),并通过INSERT将其与该用户的主要ID下的其他当前值相加。

And how would I reset the value per day? 以及每天如何重置该值? Will this need to be done manually? 是否需要手动完成? or can I do it automatically via MySQL? 还是可以通过MySQL自动完成?

You would want to set a cron job to reset the values every day. 您可能想设置一个cron作业来每天重置这些值。 Here's a great resource to get started: 这是一个很好的入门资源:

http://kb.iu.edu/data/afiz.html http://kb.iu.edu/data/afiz.html

Essentially, you display the crontab with 本质上,您可以使用以下命令显示crontab

crontab -e

then add a command to execute at the specified frequency (the example below does example.php every day at midnight): 然后添加一个命令以指定的频率执行(下面的示例每天在午夜执行example.php):

0 0 * * * /path/to/php /path/to/your/example.php

And in example.php you have the logic to reset the database values. 在example.php中,您可以使用逻辑来重置数据库值。

Two options here: 这里有两个选择:

  1. Reset the counter with a cronjob at a specific time. 在特定时间使用cronjob重置计数器。

  2. Don't have a counter, but create a log table and log each search with user-id and timestamp. 没有计数器,但是创建一个日志表并使用用户ID和时间戳记录每次搜索。 Then, before executing a search, look up how many searches a user has done within the last 24 hours and decide if they're allowed to run another. 然后,在执行搜索之前,先查看用户在过去24小时内进行了多少次搜索,然后确定是否允许他们进行其他搜索。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM