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
https://forums.phpfreaks.com/topic/181211-solved-testing-if-exists-in-array/
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];

Ok that worked great, thanks!  I was in the middle of looking at that in the manual when I got your post.  What would I do if I want to end the registration if it is not in the array?  Even if the verification is wrong it still registers the user?  Any ideas?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.