/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Help preg_matching several words

Hey guys,

I have the following code to block the word “Aloha” on my site’s guestbook. Now I’m getting spam containing a few other words, such as Viagra and other various prescriptions.

Is there an easier way to write this code?

[code=php]if ((preg_match(“/Aloha/”, $message)) || (preg_match(“/Viagra/”, $message)) || (preg_match(“/Cialis/”, $message)))
{
$errors[] = “This looks like spam. If it is, **** off.”;
}[/code]

I’m clearly a noob at PHP, but trying to learn (that why I’m writing my own guestbook thing when I know that there’s better solutions out there). I need the practice. I also know that there’s better ways to prevent spam, but I get maybe 2 posts a month and 6 spam posts, so it won’t be tough to update the list of blocked words.

Any help/criticism is appreciated. Thank you!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@dtm32236authorFeb 03.2010 — Nevermind, I got it...

[code=php]if (preg_match("/(aloha|viagra|cialis)/i", $message));
{
$errors[] = "This looks like spam. If it is, **** off.";
}[/code]


Thanks anyway!
Copy linkTweet thisAlerts:
@criterion9Feb 04.2010 — Have you tried other methods to detect spam from bots? Generally spam bots will fill every field and don't parse javascript/css. You could create a field that css hides and/or javascript populates and check against your expected response.
×

Success!

Help @dtm32236 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...