简体   繁体   中英

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)

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.

And how would I reset the value per day? Will this need to be done manually? or can I do it automatically via MySQL?

You would want to set a cron job to reset the values every day. Here's a great resource to get started:

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

Essentially, you display the crontab with

crontab -e

then add a command to execute at the specified frequency (the example below does example.php every day at midnight):

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

And in example.php you have the logic to reset the database values.

Two options here:

  1. Reset the counter with a cronjob at a specific time.

  2. Don't have a counter, but create a log table and log each search with user-id and timestamp. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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