HTML form with a PHP variable test -


i'm trying add simple php captcha code existing html web forms, using same server side php form mailer.

example form simple captcha:

<? session_start(); ?> <html> number challange test<br /> <br /> </html> <body> <? // check login - code if (isset($_request['submit'])) {      echo "running code comparison  ";     if ($_session['captcha']==$_request['code']) echo 'login ok';     else echo 'login failed'; } else { ?> <form action="<? echo $php_self ?>" method="post"> username: <input type="text" name="username" /><br /> password: <input type="text" name="password" /><br /> <img src="example.php" /> code: <input type="text" name="code" /><br /> <input type="submit" name="submit" value="login" />  </form> <? } ?> </body> </html> 

my specific question is, how can modify above form concept submit form data server-side form_mailer.php, (not submit itself) , validate 'captcha' value = 'code'?

i have tried read/display value of $_session['captcha'] (its 4 digit number) nothing echo displays value. think if (could read/display) value validate code on fly.

i'm testing use of validate button separate submit button. i'm trying accomplish 1 submit button.

example.php code:

<? session_start();  include('captcha_numbers.php'); $captcha = new captchanumbers(4); $captcha -> display();  $_session['captcha'] = $captcha -> getstring(); ?> 

source: source of code this

insted of

if (isset($_request['submit'])) {   

use

if (isset($_post['submit'])) {   

becouse using post method in form.

we don’t know code. captcha code can generated every time starts session , different then. try else.
captcha there’s simple trick placing hidden md5.
http://us2.php.net/manual/pl/function.md5.php
or stronger sha1
http://pl1.php.net/manual/en/function.sha1.php

<input type="hidden" name="captcha_md5" value="<?php echo md5($my_number); ?>"/>   

after make md5 out of code gives in form , compare it.

if ($_post['captcha_md5']==md5($_post['code'])) echo 'login ok';   

captcha gives different number every time, , md5 generates shortcut that's not possible revers. :)
luck.


Comments

Popular posts from this blog

php - SPIP: From Tag directly to an article -

jquery - isAjaxRequest always return false -

ruby on rails - In a controller spec, how to find a specific tag in the generated view? -