Jump to content

[SOLVED] Testing if exists in ARRAY


brmcdani

Recommended Posts

I recently wrote a PHP script to add to my registration page that allows for human verification by pulling random strings out of an array.  I am having trouble making my if statement work to where it checks the array before approving the user's registration.  Here is what I have so far:

 

$verification = protect($_POST['verification']);

if($verification != $rand){
        	echo "Sorry but the number verification you entered was not correct";
        }

$rand = array("asfd7", "ghdg3", "kfdr6", "sdas3", "hdsa6", "gdsd9", "ijko5");
$keys = array_rand($rand, 1);
echo "Verification letters:  ";
echo $rand[$keys];

 

Can someone please point me in the right direction?

 

Thanks

Link to comment
Share on other sites

You should check out the in_array() function...but here is what you are trying to do...I think:

 

 

 

$verification = protect($_POST['verification']);

$rand = array("asfd7", "ghdg3", "kfdr6", "sdas3", "hdsa6", "gdsd9", "ijko5");

if(!in_array($verification,$rand)){
       	echo "Sorry but the number verification you entered was not correct";
        }
$keys = array_rand($rand, 1);
echo "Verification letters:  ";
echo $rand[$keys];

Link to comment
Share on other sites

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.