FortMyersDrew Posted June 28, 2007 Share Posted June 28, 2007 Can Anyone Help Me add A Word Filter, Word Length, & Time Delay on my Shoutbox? <?php //including the database connection include('config.php'); //getting everything that has been submitted $name=mysql_real_escape_string(strip_tags($_POST['name'])); $mail=mysql_real_escape_string(strip_tags($_POST['mail'])); $message=mysql_real_escape_string(strip_tags($_POST['message'])); $submit=$_POST['submit']; //get the current time with php date() function //note that the server time will be recorded //more info about all functions - http://php.net $time=date("m/d/y - g:i a"); //get the ip. Note that this wont see through proxies $ip=$_SERVER['REMOTE_ADDR']; //just some basic error checking which //checks if name,e-mail and message //hasnt been left blank or with default text if (($name!=="") || ($name!=="Name") || ($mail!=="") || ($mail!=="E-mail") || ($message!=="") || ($message!=="Your text")) { //inserts data into the database $sql = "INSERT INTO shoutbox (id, name, mail, message, time, ip) VALUES ('NULL', '$name', '$mail', '$message', '$time', '$ip')"; mysql_query($sql) or die(mysql_error()); $query = "SELECT * FROM `shout_user_log` WHERE `ip` = '$ip'"; $result = mysql_query ($query); $num_rows = mysql_num_rows ($result); if ($num_rows > 0) { $query = "DELETE * FROM `shout_user_log` WHERE `ip` = '$ip'"; mysql_query ($query); } $query = "INSERT INTO `shout_user_log` (`id`, `username`, `email`, `ip`) VALUES ('', '$name', '$mail', '$ip')"; mysql_query ($query); //sends the user back to the form header("Location:".$_SERVER['HTTP_REFERER']); } else{ header("Location:".$_SERVER['HTTP_REFERER']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/ Share on other sites More sharing options...
FortMyersDrew Posted June 28, 2007 Author Share Posted June 28, 2007 *BUMP* Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-285171 Share on other sites More sharing options...
FortMyersDrew Posted June 29, 2007 Author Share Posted June 29, 2007 *BUMP* Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-285434 Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 You want to check the length for each individual word? Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-285448 Share on other sites More sharing options...
corbin Posted June 29, 2007 Share Posted June 29, 2007 What you're gonna need to do is add a time column to your log table. Use a integer field 10 characters long and store unix time stamps in it made from time(). Then you would want to pull the last time logged for the ip... Then you compare it to the current time minus a certain value. Forexample: $qtime = time() - 300; //only allow posts every 5 minutes $q = "SELECT time FROM shout_user_log WHERE ip = '{$ip}' AND time > '" . $qtime . "' LIMIT 1"; if(mysql_num_rows($q) > 0) { //it hasn't been 5 minutes } else { //everything passed fine } As for word length: $maxlength = 15; //15 character max on words $exp = explode(" ", $message); foreach($exp as $v) { if(strlen($v) > $maxlength) //it failed! } And then for a censor thing you could do something like $badwords = array('bad', 'another_bad_word'); str_replace($badwords, "****", $message); Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-285460 Share on other sites More sharing options...
FortMyersDrew Posted June 29, 2007 Author Share Posted June 29, 2007 So i should just add the code you have put just like so? Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286280 Share on other sites More sharing options...
FortMyersDrew Posted June 30, 2007 Author Share Posted June 30, 2007 ***BUMP*** Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286313 Share on other sites More sharing options...
ryeman98 Posted June 30, 2007 Share Posted June 30, 2007 Well... it does sound like a good idea. Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286330 Share on other sites More sharing options...
FortMyersDrew Posted June 30, 2007 Author Share Posted June 30, 2007 I have tried all of these $qtime = time() - 300; //only allow posts every 5 minutes $q = "SELECT time FROM shout_user_log WHERE ip = '{$ip}' AND time > '" . $qtime . "' LIMIT 1"; if(mysql_num_rows($q) > 0) { //it hasn't been 5 minutes } else { //everything passed fine } As for word length: $maxlength = 15; //15 character max on words $exp = explode(" ", $message); foreach($exp as $v) { if(strlen($v) > $maxlength) //it failed! } And then for a censor thing you could do something like $badwords = array('bad', 'another_bad_word'); str_replace($badwords, "****", $message); None of them work so what do i have to do to fix this Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286725 Share on other sites More sharing options...
redarrow Posted June 30, 2007 Share Posted June 30, 2007 try the time function first please ok. <?php $qtime = time() - 300; //only allow posts every 5 minutes $q = "SELECT time FROM shout_user_log WHERE ip = '$ip' AND time > '" . $qtime . "' LIMIT 1"; if(mysql_num_rows($q) > 0) { //it hasn't been 5 minutes } else { //everything passed fine } ?> Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286735 Share on other sites More sharing options...
FortMyersDrew Posted June 30, 2007 Author Share Posted June 30, 2007 Well i tried and i get this message Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/d/r/e/drewsmedia/html/doit.php on line 4 Warning: Cannot modify header information - headers already sent by (output started at /home/content/d/r/e/drewsmedia/html/doit.php:4) in /home/content/d/r/e/drewsmedia/html/doit.php on line 51 Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286737 Share on other sites More sharing options...
redarrow Posted June 30, 2007 Share Posted June 30, 2007 stick this before session_start ob_start(); Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286738 Share on other sites More sharing options...
FortMyersDrew Posted June 30, 2007 Author Share Posted June 30, 2007 It doesnt work.. it fixed the error but i can still post one after another Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286739 Share on other sites More sharing options...
redarrow Posted June 30, 2007 Share Posted June 30, 2007 in the database you got a timestamp to that set varable of time in your current query. Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286749 Share on other sites More sharing options...
FortMyersDrew Posted June 30, 2007 Author Share Posted June 30, 2007 wait what? Im so lost im new to this Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286754 Share on other sites More sharing options...
redarrow Posted June 30, 2007 Share Posted June 30, 2007 corbin code is lovly are you sure in your database you got a timstamp. Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286762 Share on other sites More sharing options...
FortMyersDrew Posted June 30, 2007 Author Share Posted June 30, 2007 This is what i use in my doit.php file //note that the server time will be recorded $time=date("m/d/y - g:i a"); Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286765 Share on other sites More sharing options...
redarrow Posted June 30, 2007 Share Posted June 30, 2007 try this then <?php $qtime = date("i") - 5; //only allow posts every 5 minutes $q = "SELECT time FROM shout_user_log WHERE ip = '$ip' AND time > '" . $qtime . "' LIMIT 1"; if(mysql_num_rows($q) > 0) { //it hasn't been 5 minutes } else { //everything passed fine } ?> Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286776 Share on other sites More sharing options...
FortMyersDrew Posted June 30, 2007 Author Share Posted June 30, 2007 do i paste that below the other <php> Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286820 Share on other sites More sharing options...
corbin Posted June 30, 2007 Share Posted June 30, 2007 Red arrow, what if someone posts at 0:00 and then they try to post at 1:00? It will give them an error even though it's been an hour since they posted. I don't think this problem would be very occurant, but it would be better to not leave that small chance of someone running into it. What is the structure of your shout_user_log table (including datatypes and lengths, please)? Quote Link to comment https://forums.phpfreaks.com/topic/57491-putting-a-word-filter-word-length-time-delay-on-shoutbox/#findComment-286849 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.