chefkevin Posted May 20, 2007 Share Posted May 20, 2007 Hi, I operate a cooking website and as such, an online recipe book that people can input their own recipes. While this is a great idea for interaction with my visitors, it has been bombarded by bots with unwanted words/URL's in the addrecipe.php that I physically have to remove. I get about 20 or so of these daily, and I don't have the time to manually handle all the deleting of "bad recipes". I've been told that by using a strpos() I will be able to ban the words/phrases I don't want in my recipe form. Can any of you provide me with a simple php script that I can put in my cookbook script to handle this? I appreciate any help you can give me on this! Thanks in advance... Chef Kevin Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/ Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 use Captcha image verification as for bad words use str_replace Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257525 Share on other sites More sharing options...
PC Nerd Posted May 20, 2007 Share Posted May 20, 2007 um..... id use an array for the words you want to filter....... and have it like: $words[0] = "word" then id loop through this array: foreach $word As $words { } than use str_replace(); to to the words: i think its like: str_replace("word_to_filet", "****", $string_name); so str_replace($word, "****", $_POST['Receipe']) you could even loop through everything in POST ( assuming your usign post to send the receipe to the script toi eneter into a database etc.....) like: for section in post, { for word in filter { filterword } } gdlk Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257526 Share on other sites More sharing options...
seb hughes Posted May 20, 2007 Share Posted May 20, 2007 use Captcha image verification Use Captcha and use an array to have the bad words in and what they will be replaced by. Heres what i mean for the array: /* Better preg_replace */ $string = 'The quick brown fox jumps over the lazy dog'; $fix = array( '/quick/' => 'fast', '/brown/' => 'php', '/fox/' => 'coder', '/jumps/' => 'speeds', '/over the lazy/' => 'everything', '/dog/' => 'up' ); /* The quick brown fox jumps over the lazy dog */ echo $string; /* The fast php coder speeds everything up */ echo preg_replace( array_keys($fix), array_values($fix), $string ); Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257529 Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 this works better <?php $string = "Blar"; $pattern[0] = '/badword1/'; $pattern[1] = '/badword2/'; $replacement[0] = '@@@@@'; $replacement[1] = '@@@@@'; $string = preg_replace($pattern, $replacement, $string); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257533 Share on other sites More sharing options...
seb hughes Posted May 20, 2007 Share Posted May 20, 2007 this works better <?php $string = "Blar"; $pattern[0] = '/badword1/'; $pattern[1] = '/badword2/'; $replacement[0] = '@@@@@'; $replacement[1] = '@@@@@'; $string = preg_replace($pattern, $replacement, $string); ?> I think the method I post is better, though it does work in the same way. But the one i posted is faster and more friendly. Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257534 Share on other sites More sharing options...
MadTechie Posted May 20, 2007 Share Posted May 20, 2007 i posted before your edit my "better one" refers to PC Nerds Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257535 Share on other sites More sharing options...
redarrow Posted May 20, 2007 Share Posted May 20, 2007 sorry but i disagree with other comment's You have told us the entry of the database is getting information you dont need so therefore you will need to add the captha but at the same time you also need to tell the user if a word exist's you dont wont in the form set a array and use a if statement to propmt the user that the information there trying to enter is not allowed. why replace an entry of words that are not wanted or let the database collect complete rubish? Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257557 Share on other sites More sharing options...
AndyB Posted May 20, 2007 Share Posted May 20, 2007 Here's one I use: // function to check for all our favorite penis extenders and othes spam trash function flag_spam($text) { $total_matches = 0; $trash = array(); // Count the regular links $regex = "/<\s*a\s+href\s*=\s*/i"; $total_matches += preg_match_all($regex, $text, $trash); // Count the PHPBB links $regex = "/\[url/i"; $total_matches += 5 * preg_match_all($regex, $text, $trash); // Check for common spam words $words = array('phentermine', 'viagra', 'cialis', 'vioxx', 'oxycontin', 'levitra', 'ambien', 'xanax', 'paxil', 'casino', 'slot-machine', 'texas-holdem'); foreach ($words as $word) { $word_matches = preg_match_all('/' . $word . '/i', $text, $trash); $total_matches += 5 * $word_matches; } if ($total_matches > 4) { return TRUE; } return FALSE; } And it's applied to a user-entered comment thus: if (flag_spam($comments)) { .. optional code .. exit; } Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257569 Share on other sites More sharing options...
chefkevin Posted May 20, 2007 Author Share Posted May 20, 2007 Hi All... Thanks for all the advice. Not to PO any of you, but out of all these I like AndyB's version the best as it simply addresses the spam issue I am dealing with. I don't want to replace any of the bad words, I want to stop the script from allowing these trash recipes to be sent through whatsoever. I do realize that I will have to create an array of the words I want to ban. One thing that needs to be addressed is the fact that I don't want the script user/bot to know their recipe is not being posted, or they will probably just alter their words (e.g viagra becomes v i a g r a). If I could have a bit more direction on this aspect, and at the risk of being a total pain (a.k.a. newbie), can you inform me of the best way to implement this into my existing php script. With gratitude!... Chef Kevin Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257762 Share on other sites More sharing options...
seb hughes Posted May 20, 2007 Share Posted May 20, 2007 Most spam now use images, also they put V1agra and crap now. Also most fo these are done via ots so you should use CAPTCHA Quote Link to comment https://forums.phpfreaks.com/topic/52214-using-strpos-to-ban-unwanted-words-in-cookbook-script/#findComment-257772 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.