brmcdani Posted November 12, 2009 Share Posted November 12, 2009 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 More sharing options...
darkvengance Posted November 12, 2009 Share Posted November 12, 2009 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 https://forums.phpfreaks.com/topic/181211-solved-testing-if-exists-in-array/#findComment-955997 Share on other sites More sharing options...
brmcdani Posted November 12, 2009 Author Share Posted November 12, 2009 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? Link to comment https://forums.phpfreaks.com/topic/181211-solved-testing-if-exists-in-array/#findComment-956000 Share on other sites More sharing options...
brmcdani Posted November 12, 2009 Author Share Posted November 12, 2009 Nevermind got it! Link to comment https://forums.phpfreaks.com/topic/181211-solved-testing-if-exists-in-array/#findComment-956001 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.