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
Share on other sites

the user has to login of course. im not sure how id be able to implement a timer system where the access limit that ive set automatically resets after 24 hours.  ughh. any suggestions or help appreciated

Link to comment
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{

}

Link to comment
Share on other sites

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!

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.