newb Posted April 3, 2008 Share Posted April 3, 2008 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? Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 3, 2008 Share Posted April 3, 2008 Are you restricting for an anonymous user, or does the user have to 'log-in' to your site? Anonymous users can be deterred, but there is no sure-fire way to limit usage. Quote Link to comment Share on other sites More sharing options...
newb Posted April 3, 2008 Author Share Posted April 3, 2008 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 Quote Link to comment Share on other sites More sharing options...
almightyegg Posted April 3, 2008 Share Posted April 3, 2008 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{ } Quote Link to comment Share on other sites More sharing options...
discomatt Posted April 3, 2008 Share Posted April 3, 2008 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! ?> Quote Link to comment Share on other sites More sharing options...
newb Posted April 3, 2008 Author Share Posted April 3, 2008 wow exactly what i was looking for, thanks a bunch matt! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.