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

Link to comment
Share on other sites

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';
}
}
Edited by ignace
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.