Rsmiley Posted November 7, 2008 Share Posted November 7, 2008 I am not the best with doing if($jhskldaf != $kjdsf) so i need some assistance and i would like some help figuring out how to do this... Its probably once again a simple fix im just to incompetent to figure it out... anyway, <tr><td width="25%"><b>Confirm Email:</b></td><td width="81%"><input type="email" name="email2"></td></tr> <?php $a1 = rand(1,3000); $a2 = rand(1,4535); $a3 = $a1+$a2 ?> <tr><td width="35%"><b>Enter the equasions answer</b> <br /><?php print "$a1 + $a2 = <b><span style='color:red'>$a3</span></b>"; ?> </b></td><td width="81%"><input type="captcha" name="captcha"></td></tr> <tr><td width="15%"><b> </b></td><td width="81%"><input type="submit" name="submit" value="Complete Registration"></td></tr> </table></form> </p> <p> <?php $user = $_POST['user']; $pass = $_POST['pass']; $pass2 = $_POST['pass2']; $email = $_POST['email']; $email2 = $_POST['email2']; $captcha = $_POST['captcha']; $pass1 = md5($pass); if(isset($_POST['submit'])) { if (!$user || !$pass || !$pass2 || !$email || !$email2 || !$captcha) { print "You failed to fill in all fields"; print "</div></div></div>"; include 'side.php'; include 'footer.php'; exit; } if($a3 != '$captcha') { print "<B><center><font size=5>CAPTCHA INCORRECT!</font></b></center>"; print "</div></div></div>"; include 'side.php'; include 'footer.php'; exit; } With if($a3 != '$captcha') { I also tried swapping the variables places and did nothing Whether you submit the proper captcha or not it still errors Demo: http://smileybb.com/flds/register.php Any Assistance from the skilled coders of PHPFreaks? Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/ Share on other sites More sharing options...
xtopolis Posted November 7, 2008 Share Posted November 7, 2008 if($a3 != '$captcha') { should be: if($a3 != $captcha) { Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/#findComment-684288 Share on other sites More sharing options...
Rsmiley Posted November 7, 2008 Author Share Posted November 7, 2008 if($a3 != '$captcha') { should be: if($a3 != $captcha) { I still get the CAPTCHA INCORRECT error Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/#findComment-684290 Share on other sites More sharing options...
PFMaBiSmAd Posted November 7, 2008 Share Posted November 7, 2008 Your code must save the $a3 value it generates when the form is output into a session variable so that the value submitted from the form will be compared with that value. Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/#findComment-684297 Share on other sites More sharing options...
.josh Posted November 7, 2008 Share Posted November 7, 2008 First off, I'm surprised you aren't getting a parse error from $a3 = $a1+$a2 seeing as how you forgot the semicolon. Second, the reason why it's not matching is because when you initially go to the page, you go through the motions of picking out 2 random numbers and adding them together and assigning that to $a3. Well when you submit the form it turns around and regenerates a new number, because you don't have that number generation part wrapped in some kind of condition...like..only generating a number if there is no form info posted. 3rd, even if you manage to sort all that out, you aren't carrying over the answer. You need to pass the info through as a hidden variable (not really secure) or as a session variable or something, so that it will persist. Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/#findComment-684302 Share on other sites More sharing options...
.josh Posted November 7, 2008 Share Posted November 7, 2008 oh and btw, even when you get all of that stuff sorted out, that's an incredibly weak captcha. It can and will be cracked in like 2s without even requiring optical devices or image recognition algorithms. Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/#findComment-684303 Share on other sites More sharing options...
Rsmiley Posted November 7, 2008 Author Share Posted November 7, 2008 First off, I'm surprised you aren't getting a parse error from $a3 = $a1+$a2 seeing as how you forgot the semicolon. Second, the reason why it's not matching is because when you initially go to the page, you go through the motions of picking out 2 random numbers and adding them together and assigning that to $a3. Well when you submit the form it turns around and regenerates a new number, because you don't have that number generation part wrapped in some kind of condition...like..only generating a number if there is no form info posted. 3rd, even if you manage to sort all that out, you aren't carrying over the answer. You need to pass the info through as a hidden variable (not really secure) or as a session variable or something, so that it will persist. I am unsure how to do this. I am not really good, at doing this captcha stuff even tho it is slightly basic. I added the simicolon and i tried sending it over in a hidden but it didnt work then again its probably more of my failure <?php $config = mysql_fetch_array(mysql_query(" SELECT * FROM `configs` ")); if($config['captcha'] == 'On') { $a1 = rand(1,3000); $a2 = rand(1,4535); $a3 = $a1+$a2; ?> <tr><td width=35%><b>Enter the equasions answer</b> <br /><?php print "$a1 + $a2 = <b><span style=color:red>$a3</span></b>"; ?> </b></td><td width=81%><input type=captcha name=captcha><input type="hidden" value="<?php print "$a3"; ?>" name="a4"></td></tr> ... if($config['captcha'] == 'On') { if($captcha != $a4) { print "<B><center><font size=5>CAPTCHA INCORRECT!</font></b></center>"; print "</div></div></div>"; include 'side.php'; include 'footer.php'; exit; } } oh and btw, even when you get all of that stuff sorted out, that's an incredibly weak captcha. It can and will be cracked in like 2s without even requiring optical devices or image recognition algorithms. I know it can be cracked easily its just a simple one as i am totally confused as to how to do an image one. Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/#findComment-684307 Share on other sites More sharing options...
xtopolis Posted November 7, 2008 Share Posted November 7, 2008 I wrote a basic one as an example answer to another question: Please bare in mind that this is a basic example that shows how to make a capture, and put text on an image. Perhaps this will make some things more clear to you. try: http://xtopolis.com/help/phpfreaks/captcha/ source: index.php <?php session_start(); //------------------ if(isset($_POST['captcha'])){ if($_POST['captcha'] == $_SESSION['security_code']){ echo '<font color="green">Success!</font>'; echo '<br />The code was: '.$_SESSION['security_code']; }else{ echo '<font color="red">WRONG</font>'; } echo '<br /><a href="index.php">Main</a>'; }else{ ?> <html> <head> </head> <body> <form method="post"> <img src="captcha.php" /> Captcha: <input type="text" name="captcha" /> <br /><input type="submit" value="Code In" /> </form> </body> </html> <?php } ?> captcha.php <?php session_start(); $md5 = md5(rand(0,999)); // security code $_SESSION['security_code'] = $md5; $my_img = imagecreate( 310, 60 ); $background = imagecolorallocate( $my_img, 92, 64, 51 ); $text_colour = imagecolorallocate( $my_img, 255, 255, 255 ); imagestring( $my_img, 5, 10, 25, $md5, $text_colour ); header( "Content-type: image/jpeg" ); imagejpeg( $my_img ); imagecolordeallocate( $line_color ); imagecolordeallocate( $text_color ); imagecolordeallocate( $background ); imagedestroy( $my_img ); $md5 = ''; ?> Quote Link to comment https://forums.phpfreaks.com/topic/131735-captcha-problem-text-not-image/#findComment-684310 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.