php - custom captcha submits form even if code is not correct -
I am using a custom captcha but submitting this form even if the code is not correct, here the index page The main code is
$ (document) .ready (function () {$ ('# send'). Click (function () {// name validation var nameVal = $ ("# name "Val (('' Label class =" error "id =" name_error "> if (nameVal == '') {$ (" # name_error "). Html (''); $ (" # Name ");) (/ '&.) + @ ([\ W -] + +.) + [\ W -] {2,4}) $ $ /; var Email Address = $ (" # Email "). Val (); if (emailaddressVal == ('& lt; label class =" error "id =" email_error "& gt; Please enter your email address. & Lt; / label & gt;';) Returned if} otherwise! ($ EmailReg.test (emailaddressVal) {$ ("# email_error"). Html (''); $ ("# Email"). ('& Lt; label class = "error" id = "Email_error" & gt; Enter a valid email address. & Lt; / label & gt; '); return false; other {$ ("# email_error"). Html (' ');} $ .post ("post .php? "+ $ (" #my_submit "). Serialize (), {}, function (response) {if (response == 1) {$ (" # after_submit "). Html (''); $ ("Send"). ('& Lt; label class = "success" id = "after_submit" & gt; your message has been submitted. & Lt; / label & gt;'); Change_captcha (); Clear_form (('& lt; label class = "error" id = "after_submit" & gt; error! Invalid captcha code. & Lt; / label & gt;';)}}); return false; }); // Refresh Captcha $ ('IMG # Refresh'). Click (function () {change_captcha ();}); Function change_captcha () {document.getElementById ('Captcha'). Src = "get_captcha.php? Rnd =" + math.random (); } Function clear_form () {$ ("# name"). Val (''); $ ("#Email") Val ('') $ ("#moded") val (''). }});
index.php code (the beginning of the session is at the beginning of the file)
& lt; Form action = "#" name = "MYFORM" id = "MYFORM" & gt; & Lt; Label & gt; Name & lt; / Labels & gt; & Lt; Input name = "name" size = "30" type = "text" id = "name" & gt; & Lt; Br = clear = "all" /> & Lt; Label & gt; Email & lt; / Labels & gt; & Lt; Input name = "email" size = "30" type = "article" id = "email" & gt; & Lt; Br = clear = "all" /> & Lt; Label & gt; Message & lt; / Labels & gt; & Lt; Textarea id = "message" name = "message" & gt; & Lt; / Textarea & gt; & Lt; Br = clear = "all" /> & Lt; Div id = "wrap" align = "center" & gt; & Lt; Img src = "get_captcha.php" alt = "" id = "captcha" /> & Lt; Br = clear = "all" /> & Lt; Input name = "code" type = "article" id = "code" & gt; & Lt; / Div & gt; & Lt; Img src = "refresh.jpg" width = "25" alt = "" id = "refresh" /> & Lt; Br = clear = "all" /> & Lt; Br = clear = "all" /> & Lt; Label & gt; & Nbsp; & Lt; / Labels & gt; & Lt; Input value = "send" type = "submit" id = "send" & gt; & Lt; / Form & gt;
post.php code
session_start (); If (@ $ _ request ['code'] || @strolover ($ _ request ['code']) == stroller ($ _ session ['random_number'])) {echo 1; // submitted} and {echo 0; // invalid code}
get_captcha.php file
session_start (); $ String = ''; For ($ i = 0; $ i & lt; 5; $ i ++) {$ string} = Chr (Rand (97, 122)); } $ _SESSION ['random_number'] = $ string; $ Dir = 'fonts /'; $ Image = imagecreatetruecolor (165, 50); $ Num = Rand (1,2); If ($ num == 1) {$ font = "Capture it 2.ttf"; // font style} and {$ font = "Molot.otf"; // font style} $ num2 = rand (1,2); If ($ num2 == 1) {$ color = imagecolorallocate ($ image, 113, 193, 217); // color} and ($ color = imagecolorallocate ($ image, 163, 197, 82); // color} $ White = imagecolorallocate ($ image, 255, 255, 255); // background color white imageFilterGanglele ($ image, 0,0,399, 99, $ white); Fictional picture ($ image, 30, 0, 10, 40, $ color, $ dir. $ Font, $ _SESSION ['random_number']); Header ("Content -type: image / PNG "); imagepng ($ image);
Here is the full code
There should probably be one & amp; amp; in the post.php code; Otherwise, unless $ _REQUEST ['code'] is not empty, this will execute echo 1.
session_start (); if ( @ $ _ Request ['code'] & amp; amp; @strtolower ($ _ request ['code']) == stroller ($ _ session ['random_number'])) {echo 1; // submitted} And {echo 0; // invalid code}
Comments
Post a Comment