quickstopman Posted July 9, 2007 Share Posted July 9, 2007 im working on a homemade forum for my site and im trying to make a way to stop a person from being able to post more than 10 posts in 4 minutes (or what ever is a good time frame). and if the user does this more than 3 times there account gets deleted can someone instruct me on how to do this ?? thanks Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/ Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 i dont think you would want to delete them just notify them that they cant post for 20 mins but just use the time then add a certain amount of time and then check it with the current time Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-292978 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 so should i make a mysql row in the user database with the amount of posts?? and make another that tells if that user can post or not??? and then in the header file it checks to see the time each time it refreshes the page? Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-292981 Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 um i wouldnt make either do somin like: <?php $access = "Allow"; $i = 0; $time = time(); $query = mysql_query("SELECT * FROM posts WHERE timeposted<($time-(60*4))"); while($info = mysql_fetch_array($query)) { $i++; if($i>=10) { $access = "Deny"; } } if($access="Deny") { echo("Sorry you can't post you have posted to many times."); }else{ \\go ahead } ?> Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-292984 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 so i should but that in the header file? or on the post page? Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-292989 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 i understand what you doing but i keep getting this error now Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pokebash/public_html/getmetola/tests/gamecoders/post.php on line 13 here is the code i have: <?php ob_start(); session_start(); include("ZZcode.h"); include("header.php"); include("config.php"); if(isset($_SESSION['email'])) { $access = "Allow"; $i = 0; $time = time(); $query = mysql_query("SELECT * FROM posts WHERE time_posted<($time-(60*4) posted_by = '{$_SESSION['id']}'"); while($timeinfo = mysql_fetch_array($query)) { $i++; if($i>=10) { $access = "Deny"; } } if($access="Deny") { echo("Sorry you can't post you have posted to many times."); }else{ if($_POST['submit']) { $errors = array(); $topic = $_POST['topic']; $content = $_POST['content']; if (empty($topic) && empty($content)) { echo ' <font color="red">Please Fill in All the forms!</font><br><br> '; echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } else { if(isset($_SESSION['email'])) { $query = "INSERT INTO post (topic, content, time_posted , reply_to, posted_by) VALUES ('$topic', '$content', '', '$topic', '{$_SESSION['id']}')"; $result = @mysql_query($query) or die(mysql_error()); echo "Thanks for posting your topic!<br> you can view your topic <a href='posts.php'>here</a><br>"; } else { echo "you can't remotly access this form!!! SUX FOR YOU HAXOR!!!!!"; } } } else { echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } } } else { echo "You must be logged in to post a forum topic"; } ?> anyideas? i think its in the while statement Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-292994 Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 fix the query: $query = mysql_query("SELECT * FROM posts WHERE time_posted<($time-(60*4) posted_by = '{$_SESSION['id']}'"); to $query = mysql_query("SELECT * FROM posts WHERE time_posted<($time-(60*4)) AND posted_by = '{$_SESSION['id']}'"); Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293004 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 im still getting the same error i think it might be because in the while statement you never use the declared variable what do you think other than that? Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293006 Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 can i see the updated php and where you are runing this at? Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293011 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 oh!!!!!!!!! you had the wrong table name it was post not posts thanks but now it says even if i haven't posted anything that ive posted too many Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293012 Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 can i see the code? Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293024 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 <?php ob_start(); session_start(); include("ZZcode.h"); include("header.php"); include("config.php"); if(isset($_SESSION['email'])) { $access = "Allow"; $i = 0; $time = time(); $query2 = mysql_query("SELECT * FROM post WHERE time_posted<($time-(60*4)) AND posted_by = '{$_SESSION['id']}'"); while($time = mysql_fetch_array($query2)) { $i++; if($i>=10) { $access = "Deny"; } } if($access="Deny") { echo("Sorry you can't post you have posted to many times."); } else if($access="Allow") { if($_POST['submit']) { $errors = array(); $topic = $_POST['topic']; $content = $_POST['content']; if (empty($topic) && empty($content)) { echo ' <font color="red">Please Fill in All the forms!</font><br><br> '; echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } else { if(isset($_SESSION['email'])) { $query = "INSERT INTO post (topic, content, time_posted , reply_to, posted_by) VALUES ('$topic', '$content', '', '$topic', '{$_SESSION['id']}')"; $result = @mysql_query($query) or die(mysql_error()); echo "Thanks for posting your topic!<br> you can view your topic <a href='posts.php'>here</a><br>"; } else { echo "you can't remotly access this form!!! SUX FOR YOU HAXOR!!!!!"; } } } else { echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } } } else { echo "You must be logged in to post a forum topic"; } ?> Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293027 Share on other sites More sharing options...
BillyBoB Posted July 9, 2007 Share Posted July 9, 2007 sorry if i misslead you but the query should be $query2 = mysql_query("SELECT * FROM post WHERE time_posted>($time-(60*4)) AND posted_by = '{$_SESSION['id']}'"); i might have typed it in wrong the first time but the time has to be greater than the time 4 mins ago Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293029 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 its still not working but i also am gonna call it a night its 12:55 here night guys Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293030 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 does anyone have a clue how to make this work? Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293534 Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 Maybe something like this? <?php $qry = mysql_query("SELECT COUNT(*) as pcount FROM post WHERE time_posted<(ADDTIME(NOW(),'00:04:00.00')) AND posted_by = '{$_SESSION['id']}'"); $qr = mysql_fetch_row($qry); if ( $qr['pcount'] > 4 ) { // deny } ?> I didn't test this, of course. Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293547 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 i get that code cause it looks like it works but what is pcount should i add that into my users table? Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293551 Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 Nah, pcount is an alias to COUNT(*), basically just a count of how many rows (posts) were found that matched your where condition. Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293555 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 cool Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293564 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 now when i submit i get this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 here is the code so far <?php ob_start(); session_start(); include("ZZcode.h"); include("header.php"); include("config.php"); if(isset($_SESSION['email'])) { $qry = mysql_query("SELECT COUNT(*) as pcount FROM post WHERE time_posted<(ADDTIME(NOW(),'00:04:00.00')) AND posted_by = '{$_SESSION['id']}'"); $qr = mysql_fetch_row($qry); if ( $qr['pcount'] > 4 ) { echo "You cannot post any more posts for the next 10 minutes, you may have been spamming!!"; } else if ($qr['pcount'] < 4) { if($_POST['submit']) { $errors = array(); $topic = $_POST['topic']; $content = $_POST['content']; if (empty($topic) && empty($content)) { echo ' <font color="red">Please Fill in All the forms!</font><br><br> '; echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } else { if(isset($_SESSION['email'])) { $query = "INSERT INTO post (topic, content, time_posted , reply_to, posted_by) VALUES ('$topic', '$content', '', '$topic', '{$_SESSION['id']}'"; $result = @mysql_query($query) or die(mysql_error()); echo "Thanks for posting your topic!<br> you can view your topic <a href='posts.php'>here</a><br>"; } else { echo "you can't remotly access this form!!! SUX FOR YOU HAXOR!!!!!"; } } } else { echo ' <form action="'. $_SERVER['PHP_SELF'] .'" method="POST"> Topic: <input name="topic" type="text"><br><br> Post Content:<br> <textarea cols="32" rows="10px" name="content"></textarea><br> <input type="submit" name="submit" value="Post Topic"> </form> '; } } } else { echo "You must be logged in to post a forum topic"; } ?> Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293566 Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 Not sure what that's about, but another note, I used mysql_fetch_row, might want to try mysql_fetch_assoc(), and change 4 to 10.. I dunno, I'm tired, sorry Hmm, I also changed the 'time_posted' check. Checking all posted less than 4 minutes from now was wrong. Should check all posted -4 minutes from now, hah. <?php $qry = mysql_query("SELECT COUNT(*) as pcount FROM post WHERE time_posted>DATE_SUB(NOW(), INTERVAL 4 MINUTES) AND posted_by = '{$_SESSION['id']}'"); $qr = mysql_fetch_assoc($qry); if ( $qr['pcount'] > 10 ) { // deny } ?> Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293586 Share on other sites More sharing options...
quickstopman Posted July 9, 2007 Author Share Posted July 9, 2007 it said that that your have an invalid argument for mysql_fetch_assoc so i changed it back to its original state and fixed the other error that was in my code not yours but now it still doesn't work Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293598 Share on other sites More sharing options...
no_one Posted July 9, 2007 Share Posted July 9, 2007 okay, fetch_array or something :'( I'd think the query is fine though, for the most part. Link to comment https://forums.phpfreaks.com/topic/59021-limits-posts-per-10-minutes/#findComment-293599 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.