scferg Posted February 13, 2008 Share Posted February 13, 2008 Well, I was told to start a topic here about my question, so I am. I was referred to this CAPTCHA script for my forms. I have made those 3 files, and have got them the way I want them, but I have an issue. My forms already have action values, so I can't have the action=result.php code for the CAPTCHA to work. All of my form have an action value of http://mysite.com/v-cgi/forms.cgi. And if I get passed that problem, I have another issue. The result of the CAPTCHA either is "Code in correct" or "Code is incorrect." Well, I need the form to submit if the code is correct (instead of just saying the numbers are valid). So, if anybody has any help to offer, I'd really appreciate it. Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/ Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 I'm not going to read that captcha, but the way they work is 1) You have an image that is generated from a php script, that script sends that code into a session. 2) The image contains a visual way to see the code. The user inputs this 3) Your processor page then should check that the $_POST['catpcha'] == $_SESSION['captcha'] so you don't need to alter anything just generate the image, most of the image generators also do the session creation with the image script Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465444 Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 Well, my forms are weird...and the only thing I know how to do with php is a simple include statement. To see how my forms work, try one out here: http://sims2news.com/?page=contact I've added the CAPTCHA validation image and input box, but the result.php page is not in the action value. The result.php file is where the validation code is checked to see if it's correct or not. So, it's like I need two action values... :-\ Sorry for my lack of knowledge about this. Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465447 Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 no you don't show us image.php and basicalyl what ever session it sets make sure $_POST['num'] == $_SESSION['Captcha'] Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465454 Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 The script requires 3 files. image.php (self explanatory) <?php // Font directory + font name $font = 'fonts/Disney.ttf'; // Total number of lines $lineCount = 40; // Size of the font $fontSize = 40; // Height of the image $height = 50; // Width of the image $width = 150; $img_handle = imagecreate ($width, $height) or die ("Cannot Create image"); // Set the Background Color RGB $backColor = imagecolorallocate($img_handle, 255, 255, 255); // Set the Line Color RGB $lineColor = imagecolorallocate($img_handle, 175, 238, 238); // Set the Text Color RGB $txtColor = imagecolorallocate($img_handle, 135, 206, 235); // Do not edit below this point $string = "abcdefghijklmnopqrstuvwxyz0123456789"; for($i=0;$i<6;$i++){ $pos = rand(0,36); $str .= $string{$pos}; } $textbox = imagettfbbox($fontSize, 0, $font, $str) or die('Error in imagettfbbox function'); $x = ($width - $textbox[4])/2; $y = ($height - $textbox[5])/2; imagettftext($img_handle, $fontSize, 0, $x, $y, $txtColor, $font , $str) or die('Error in imagettftext function'); for($i=0;$i<$lineCount;$i++){ $x1 = rand(0,$width);$x2 = rand(0,$width); $y1 = rand(0,$width);$y2 = rand(0,$width); imageline($img_handle,$x1,$y1,$x2,$y2,$lineColor); } header('Content-Type: image/jpeg'); imagejpeg($img_handle,NULL,100); imagedestroy($img_handle); session_start(); $_SESSION['img_number'] = $str; ?> form.php (a form showing it in action) <form action="result.php" method="post"> <img alt="Random Number" src="image.php"> <input type="text" name="num"><br> <input type="submit" name="submit" value="Check"> </form> result.php (where the code is checked) <?php session_start(); if($_SESSION['img_number'] != $_POST['num']){ echo'The number you entered doesn\'t match the image.<br> <a href="form.php">Try Again</a><br>'; }else{ echo'The numbers Match!<br> <a href="form.php">Try Again</a><br>'; } ?> And I still don't get what you are saying about $_POST['num'] == $_SESSION['Captcha'] Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465459 Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 your result.php looks fine whats the issue??? Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465463 Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 I need the code to work with this form: Which already has an action value (not result.php). Therefore, the CAPTCHA code is not checked for validity. <form action="http://mysite.com/v-cgi/forms.cgi" enctype="application/x-www-form-urlencoded" method="post"> <table style="font-family: helvetica; font-size: 12px;"> <tr> <th align="right"> Name: </th> <td> <input class="input" type="text" name="Name" size="30" /> </td> </tr> <tr> <th align="right"> Email Address: </th> <td> <input class="input" type="text" name="Email_Address" size="30" /> </td> </tr> <tr> <th align="right"> Message Subject: </th> <td> <input class="input" name="Message_Subject" size="30" /> </td> </tr> <tr valign="top"> <th align="right"> Message: </th> <td> <textarea class="input2" name="Message" rows="6" cols="30"></textarea> </td> </tr> <tr valign="top"> <th align="right"> Validation: </th> <td> <img style="margin-bottom:5px;" alt="Random Number" src="http://sims2news.com/image.php"><br /> <input class="input" type="text" name="num" size="30" /> </td> </tr> <tr> <th></th> <td> <input class="submit" type="submit" name="Submit" value="Submit" onclick="submitForm();" /> <input class="submit" type="reset" name="Submit" value="Reset" /> </td> </tr> </table><input type="hidden" name="_FORMID" value="###" /> </form> Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465466 Share on other sites More sharing options...
cooldude832 Posted February 13, 2008 Share Posted February 13, 2008 You can't. Its a CGI form you have to add an intermediate php page to verify the captcha and then forward push the data to the cgi page. Or rewrite your cgi to be php or write your captcha into your cgi Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465471 Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 Well, I certainly don't know how to do that Oh well... Thanks for the help though! Quote Link to comment https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465474 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.