PHP Spam check code help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

PHP Spam check code help

Post by tomsace »

Hey,
I have a code on my site which tells the user to enter a 'spam check' number when filling out a contact form.
Basically it only allows one number to be written into the box, any number of my choice.
My question is how can I edit it to allow multiple numbers to be inserted into the box?

The code goes something like this:

Code: Select all

else if(trim($spamcheck) != '12345')
Thanks.
User avatar
php_east
Forum Contributor
Posts: 453
Joined: Sun Feb 22, 2009 1:31 pm
Location: Far Far East.

Re: PHP Spam check code help

Post by php_east »

you could ask user to enter several numbers comma delimited and then use
explode(',',$spamcheck) and check that all entries in the array matches your multiple numbers.

or u could also use space as a delimiter. whatever suits you.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Spam check code help

Post by califdon »

tomsace wrote:Hey,
I have a code on my site which tells the user to enter a 'spam check' number when filling out a contact form.
Basically it only allows one number to be written into the box, any number of my choice.
My question is how can I edit it to allow multiple numbers to be inserted into the box?

The code goes something like this:

Code: Select all

else if(trim($spamcheck) != '12345')
Thanks.
Are you asking how to make the box larger?? If so, change the SIZE= parameter in the <INPUT...> tag.
tomsace
Forum Contributor
Posts: 167
Joined: Thu Jan 01, 2009 8:07 pm

Re: PHP Spam check code help

Post by tomsace »

califdon wrote:
tomsace wrote:Hey,
I have a code on my site which tells the user to enter a 'spam check' number when filling out a contact form.
Basically it only allows one number to be written into the box, any number of my choice.
My question is how can I edit it to allow multiple numbers to be inserted into the box?

The code goes something like this:

Code: Select all

else if(trim($spamcheck) != '12345')
Thanks.
Are you asking how to make the box larger?? If so, change the SIZE= parameter in the <INPUT...> tag.

Hi,
No, I am asking how to allow several different codes to be used. So the user could either use 12354, or 71625, or 93728 etc...

Tom.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Spam check code help

Post by califdon »

tomsace wrote:Hi,
No, I am asking how to allow several different codes to be used. So the user could either use 12354, or 71625, or 93728 etc...

Tom.
Oh. It all depends on how you will determine what values are acceptable. If you just need to have a few values, you could code them in an array and use the function array_search() like this:

Code: Select all

$try = '71635';
  $pwds = array('12345','71625','93728');
  if(array_search($try,$pwds)) {
    echo "It matches";
  } else {
    echo "It doesn't match";
  }
Post Reply