so created own php captcha, method of creating it:
i have table in database named 'captchas' , in table, have 2 categories: id , captcha.
on captcha page how set up:
$record = mysql_query("select * captchas order rand() limit 1"); while($row=mysql_fetch_array($record)){ $captcha = $row['captcha']; echo $captcha; }
then have form 2 inputs, text , submit
i have following code form:
echo "<form method='post'>"; if(isset($_post['submit'])){ $input_captcha = $_post['input_captcha']; if($input_captcha == $captcha){ echo "<p>correct captcha.</p>"; } else { echo "<p>incorrect captcha.</p>"; } } echo "<input type='text' name='input_captcha'/>"; echo "<input type='submit' name='submit'/>"; echo "</form>"; }
what code checks if user's input equal captcha echos 'correct captcha' , if not, 'incorrect catpcha'. though, problem checks if inputted text equal next captcha number in randomized array. have no idea why happening?
what think happening is reloading variable captcha when try check user input. first make instead of saving local variable, make save session variable. try making captcha generator function , have called when session variable captcha not set, therefore stopping overwriting variable use @ later time.
this how go:
- is captcha variable set? yes or no: no (we loaded page nothing set)
- proceed generate new captcha session variable
- now when check user input against captcha, try , regenerate ask if session variable set first. find out in fact set , not generate again.
that should result in comparing against same 2 variables.