Setting the meter on a daily basis

For our recent project, we need to include a date-based counter.

for example, the pageview counter for answer.php is set in the mysql table named counter

daily access is answer.phplimited to 150 (page views). countereach access will be stored in the table , and when the daily allowance of 150 is completed, then a warning is issued about exceeding the limit and blocking the display.

but I cannot understand how this can be done daily. I mean, when the reset counter starts the next day and starts at 0.

+3
source share
5 answers

The curdate function returns the current date, so something similar to this:

$sql = "SELECT count(*) from logintable where 'logindate' = CURDATE()";

, , , . , , . .

+2

@stefgosselin , ; , < 150, . 150 , , .

0

150 ??? , . , , , "", , , .

, , ( - ) reset, ..

UserLoginTable set RequestCount = 0

.

0
source

You create a table called loginlog (log of all logins)

table loginlog
  id integer autoincrement primary key
  user_id integer
  logindate date
  logincount integer

unique key userdate(user_id, logindate)

Then you create a trigger before updating in the table

DELIMITER $$

CREATE TRIGGER bu_loginlog_each BEFORE UPDATE ON loginlog FOR EACH ROW
BEGIN
  /*Force an error by selecting from a non-existing table*/
  /*this will prevent the update*/
  IF new.logincount > 150 THEN SELECT * FROM create_error_only_150_logins_allowed
END $$

DELIMITER ;

In your php code follow these steps:

INSERT INTO loginlog (user_id, logindate, logincount) 
  VALUES ('$user_id',curdate(),1)
  ON DUPLICATE KEY UPDATE logincount = logincount + 1

Check if insert failed. If the insert / update failed, your user has logged in> 150 times, and you can refuse the user.

This will only contain one entry per user per day. You can even delete past days from the loginlog table after x days.

0
source

You need a table that displays dates in page views

-1
source

All Articles