Jump to content

Recommended Posts

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

 

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

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 );

this works better

 

 

<?php
$string = "Blar";
$pattern[0] = '/badword1/';
  $pattern[1] = '/badword2/';
  $replacement[0] = '@@@@@';
  $replacement[1] = '@@@@@';

  $string = preg_replace($pattern, $replacement, $string);
?>

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.

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?

 

 

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;
}

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

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.