Jump to content

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/90808-form-captcha-help/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465444
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465447
Share on other sites

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']

Link to comment
https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465459
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/90808-form-captcha-help/#findComment-465466
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.