Page 1 of 1

PHP Spam check code help

Posted: Sat Feb 28, 2009 8:30 am
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.

Re: PHP Spam check code help

Posted: Sat Feb 28, 2009 12:01 pm
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.

Re: PHP Spam check code help

Posted: Sat Feb 28, 2009 12:35 pm
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.

Re: PHP Spam check code help

Posted: Sun Mar 01, 2009 6:38 am
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.

Re: PHP Spam check code help

Posted: Sun Mar 01, 2009 1:14 pm
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";
  }