Jump to content

[SOLVED] HELP! HOW TO LIMIT AMOUNT/PER DAY??


newb

Recommended Posts

i need to limit the amount of times a user can access a page per day before he is denied access -- then in 24 hours, the limit resets back to normal.

 

im not sure how i would go about setting this up in php, how do i set up some sort of timer that triggers the limit reset once 24 hours comes?

Link to comment
https://forums.phpfreaks.com/topic/99430-solved-help-how-to-limit-amountper-day/
Share on other sites

on the page have an update to column in the user table

 

update users set pageview+1 etc...

 

and then an if

if($user[pageview] >= x amount){

insert timestamp

if($timestamp was more than 24 hours ago){

reset timestamp to 0 and pageviews.

echo "Please refresh to see this page.";

}else{

echo "You've viewed this page too many times in the past 24 hours.";

}

 

}else{

}

You could do it this way...

 

Assuming you have a table with the following columns

user, viewcount, timestamp

 

<?php

$q = "SELECT `timestamp`, `viewcount` FROM `table` WHERE `user` = '$user'";
$r = mysql_query($q);
list($timestamp, $viewcount) = mysql_fetch_row($r);

$now = time();
$then = $now - (24*60*60);

$maxviews = 5;

if ($timestamp > $then && $viewcount >= $maxviews)
// 24 hours hasn't expired, views are equal to or greater than max
exit('You have reached maximum views.');

elseif ($timestamp <= $then)
// 24 hours has expired, reset the view count and timer
mysql_query("UPDATE `table` SET `timestamp` = UNIX_TIMESTAMP(), `viewcount` = 1 WHERE `user` = '$user'");
else
// 24 hours has not expired, but view aren't equal to or greater than max
mysql_query("UPDATE `table` SET `viewcount` = ".$viewcount++." WHERE `user` = '$user'");

// Display content!

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.