Edit
How can I rewrite this PHP code for POST[ 'phrase' ] == session[ 'phrase' ] ?
psuedo-code
//process_form.php
PHP
session_start()
IF POST SUBMIT
IF empty text1 && empty text2
开发者_如何学JAVA echo error msg, include HTML FORM
ELSE IF empty radiobtn
echo error msg, include HTML FORM
ELSE IF
isset POST[phrase] isstring POST[phrase] isset SESSION[phrase]
strlen POST[phrase] > 0 strlen SESSION[phrase] > 0
POST[phrase] == SESSION[phrase]
SQL INSERT
ELSE
echo POST[phrase]
echo SESSION[phrase]
ELSE
include HTML FORM
/PHP
FORM
PHP
PEAR CAPTCHA Settings ...
require_once 'Text/captcha.php'
/PHP
HTML
FORM METHOD POST process_form.php
text1
text2
radio
PHP echo [ img src= sha1(session_id()) . '.png?' . time() ] /PHP
submit
/HTML
You can use this for your captcha http://www.desarrolloweb.com/articulos/poner-captcha-en-3-pasos.html
Try to use implemented captcha instead of make yours, because is much more probably that these captchas are hard tested now.
I'm not sure if you put session_start() after some html code is right. Since i remenber you receive an error like "Headers already sent". Check that just for be sure
Cheers.
If you're willing to dive a bit into Zend Form (it's worth it), look into this answer's Default_Form_ReCaptcha. Here's how you might use it without the ZF stack:
$form = new Default_Form_ReCaptcha();
if (! empty($_POST)) {
if ($form->isValid($_POST)) {
// valid captcha was entered!
$values = $form->getValues(); // all form values
}
}
$formHtml = (string)$form;
精彩评论