Jump to content

Security Question Problem


CBaZ

Recommended Posts

I have this simple script I started but for some reason it doesn't continue even if the right answer is given.

Also how would I go about adding multiple questions?

 

<?php
//simple captcha
if(isset($_POST['answer']) && $_POST['answer']!='') { echo "<script>alert('You provided a wrong answer for the Security Question')</script>"; 
echo "<a href='cabbie.php'>Please return to the Form and try again.</a><br /><br />\n";
exit; 
} else 
if(isset($_POST['answer']) && $_POST['answer']!='blue') { 

//This is the problem script above of course my code continues here.

 

 

Link to comment
https://forums.phpfreaks.com/topic/275102-security-question-problem/
Share on other sites

That entering anything at all as the answer will trigger that branch to execute.

 

Given that the message is about entering the wrong answer, shouldn't the condition check to see if you entered the wrong answer? Hint: you do it a couple lines lower.

if (isset($_POST['answer'])) {
// user posted something.. can be anything at this point (except null)
if ($_POST['answer'] == 'blue') {
// he posted blue
} elseif ($_POST['answer'] == '') {
// he just submitted the form without entering anything (show the form)
} else {
// he entered something other then blue or empty (show the form)
echo $_POST['answer'] === 'pink' ? 'You silver-tongued devil you!' : $_POST['answer'] . ' is not correct';
}
}

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.