 |
|
|
03-28-2009, 02:36 PM
|
Captcha Problem!
|
Posts: 286
Name: Adam
Location: Eastern Shore, MD, USA
|
I noticed that out of the blue my contact form located at www.bkriegtech.net/?page=contact stopped working. It's just saying that the captcha string is invalid. Below is the code from a few pages:
processor.php
Code:
<?php
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
session_start();
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {
mail("support@bkriegtech.net","Support Inquiry from Website","Form data:
Name: " . $_POST['field_1'] . "
E-Mail Address: " . $_POST['field_2'] . "
Username: " . $_POST['field_3'] . "
Problem Type: " . $_POST['field_4'] . "
Details: " . $_POST['field_5'] . "
.
");
include("confirm.html");
}
else {
echo "You have entered an invalid captcha string, please go back and try again.";
}
?>
form.php (included in the link above with a php include)
Code:
<link rel="stylesheet" type="text/css" href="calendar/calendar-blue2.css" />
<script type="text/javascript" src="calendar/calendar.js"></script>
<script type="text/javascript" src="calendar/calendar-en.js"></script>
<script type="text/javascript" src="calendar/calendar-setup.js"></script>
<SCRIPT type=text/javascript>
<!--
function collapseElem(obj)
{
var el = document.getElementById(obj);
el.style.display = 'none';
}
function expandElem(obj)
{
var el = document.getElementById(obj);
el.style.display = '';
}
//-->
</SCRIPT>
<SCRIPT type=text/javascript>
<!--
// collapse all elements, except the first one
function collapseAll()
{
var numFormPages = 1;
for(i=2; i <= numFormPages; i++)
{
currPageId = ('mainForm_' + i);
collapseElem(currPageId);
}
}
//-->
</SCRIPT>
<SCRIPT type=text/javascript>
<!--
function validateField(fieldId, fieldBoxId, fieldType, required)
{
fieldBox = document.getElementById(fieldBoxId);
fieldObj = document.getElementById(fieldId);
if(fieldType == 'text' || fieldType == 'textarea' || fieldType == 'password' || fieldType == 'file' || fieldType == 'phone' || fieldType == 'website')
{
if(required == 1 && fieldObj.value == '')
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}
}
else if(fieldType == 'menu' || fieldType == 'country' || fieldType == 'state')
{
if(required == 1 && fieldObj.selectedIndex == 0)
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}
}
else if(fieldType == 'email')
{
if((required == 1 && fieldObj.value=='') || (fieldObj.value!='' && !validate_email(fieldObj.value)))
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}
}
}
function validate_email(emailStr)
{
apos=emailStr.indexOf("@");
dotpos=emailStr.lastIndexOf(".");
if (apos<1||dotpos-apos<2)
{
return false;
}
else
{
return true;
}
}
function validateDate(fieldId, fieldBoxId, fieldType, required, minDateStr, maxDateStr)
{
retValue = true;
fieldBox = document.getElementById(fieldBoxId);
fieldObj = document.getElementById(fieldId);
dateStr = fieldObj.value;
if(required == 0 && dateStr == '')
{
return true;
}
if(dateStr.charAt(2) != '/' || dateStr.charAt(5) != '/' || dateStr.length != 10)
{
retValue = false;
}
else // format's okay; check max, min
{
currDays = parseInt(dateStr.substr(0,2),10) + parseInt(dateStr.substr(3,2),10)*30 + parseInt(dateStr.substr(6,4),10)*365;
//alert(currDays);
if(maxDateStr != '')
{
maxDays = parseInt(maxDateStr.substr(0,2),10) + parseInt(maxDateStr.substr(3,2),10)*30 + parseInt(maxDateStr.substr(6,4),10)*365;
//alert(maxDays);
if(currDays > maxDays)
retValue = false;
}
if(minDateStr != '')
{
minDays = parseInt(minDateStr.substr(0,2),10) + parseInt(minDateStr.substr(3,2),10)*30 + parseInt(minDateStr.substr(6,4),10)*365;
//alert(minDays);
if(currDays < minDays)
retValue = false;
}
}
if(retValue == false)
{
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
fieldObj.focus();
return false;
}
}
//-->
</SCRIPT>
<body onLoad="collapseAll()">
<div id="mainForm">
<div id="formHeader">
<p class="formInfo"></p>
</div>
<br/>
<form method=post enctype=multipart/form-data action=http://www.bkriegtech.net/contactform/processor.php onSubmit="return validatePage1();">
<table id="mainForm_1" class="mainForm">
<font size="2" color="#D3D3D3">
<tr><td><font size="2" color="#D3D3D3">Name: *</td><td><input type=text name=field_1 id=field_1 size='30' value='' /></td></tr>
<tr><td><font size="2" color="#D3D3D3">Email Address: *</td><td><input type=text name=field_2 id=field_2 size='30' value=''></td></tr>
<tr><td><font size="2" color="#D3D3D3">Username:</td><td><input type=text name=field_3 id=field_3 size='30' value=''></td></tr>
<tr><td><font size="2" color="#D3D3D3">Problem Type: *</td><td><select name=field_4 id=field_4>
<option value=''></option>
<option value="Testimonial">Testimonial</option><option value="Low">Low</option>
<option value="Medium">Medium</option>
<option value="High">High</option><option value="Urgent">Urgent</option>
<option value="Critical">Critical</option></select></td></tr>
<tr><td><font size="2" color="#D3D3D3">Details*:</td><td><textarea align="right" name=field_5 id=field_5 rows=10 cols=30></textarea></td></tr>
<tr><td><font size="2" color="#D3D3D3">Please type the letters in the image.</span><BR><img src="http://www.bkriegtech.net/contactform/CaptchaSecurityImages.php" /></td><td valign="bottom"><input align="right" id="captchaForm" name="security_code" type="text" /></td></tr>
<tr><td colspan="2"><br /><br /><center><input id="saveForm" type="submit" value="Submit" /></center></td></tr>
</table>
</form>
<SCRIPT type=text/javascript>
<!--
function validatePage1()
{
retVal = true;
if (validateField('field_1','fieldBox_1','text',1) == false)
retVal=false;
if (validateField('field_2','fieldBox_2','text',1) == false)
retVal=false;
if (validateField('field_3','fieldBox_3','text',0) == false)
retVal=false;
if (validateField('field_4','fieldBox_4','menu',1) == false)
retVal=false;
if (validateField('field_5','fieldBox_5','textarea',1) == false)
retVal=false;
if(retVal == false)
{
alert('Please correct the errors. Fields marked with an asterisk (*) are required');
return false;
}
return retVal;
}
//-->
</SCRIPT>
</ul></div><div id="footer"></div>
CaptchaSecurityImages.php
Code:
<?php
session_start();
class CaptchaSecurityImages {
var $font = 'monofont.ttf';
function generateCode($characters) {
/* list all possible characters, similar looking characters and vowels have been removed */
$possible = '23456789bcdfghjkmnpqrstvwxyz';
$code = '';
$i = 0;
while ($i < $characters) {
$code .= substr($possible, mt_rand(0, strlen($possible)-1), 1);
$i++;
}
return $code;
}
function CaptchaSecurityImages($width='120',$height='40',$characters='6') {
$code = $this->generateCode($characters);
/* font size will be 75% of the image height */
$font_size = $height * 0.75;
$image = @imagecreate($width, $height) or die('Cannot initialize new GD image stream');
/* set the colours */
$background_color = imagecolorallocate($image, 255, 255, 255);
$text_color = imagecolorallocate($image, 20, 40, 100);
$noise_color = imagecolorallocate($image, 100, 120, 180);
/* generate random dots in background */
for( $i=0; $i<($width*$height)/3; $i++ ) {
imagefilledellipse($image, mt_rand(0,$width), mt_rand(0,$height), 1, 1, $noise_color);
}
/* generate random lines in background */
for( $i=0; $i<($width*$height)/150; $i++ ) {
imageline($image, mt_rand(0,$width), mt_rand(0,$height), mt_rand(0,$width), mt_rand(0,$height), $noise_color);
}
/* create textbox and add text */
$textbox = imagettfbbox($font_size, 0, $this->font, $code) or die('Error in imagettfbbox function');
$x = ($width - $textbox[4])/2;
$y = ($height - $textbox[5])/2;
imagettftext($image, $font_size, 0, $x, $y, $text_color, $this->font , $code) or die('Error in imagettftext function');
/* output captcha image to browser */
imagejpeg($image);
imagedestroy($image);
$_SESSION['security_code'] = $code;
}
}
$width = isset($_GET['width']) ? $_GET['width'] : '120';
$height = isset($_GET['height']) ? $_GET['height'] : '40';
$characters = isset($_GET['characters']) ? $_GET['characters'] : '6';
header('Content-Type: image/jpeg');
$captcha = new CaptchaSecurityImages($width,$height,$characters);
?>
|
|
|
|
03-28-2009, 04:04 PM
|
Re: Captcha Problem!
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
My guess is that the security code being served is not corresponding with the images. Try echoing $_POST['security_code'] and $_SESSION['security_code'] and see what you get.
|
|
|
|
03-28-2009, 05:09 PM
|
Re: Captcha Problem!
|
Posts: 286
Name: Adam
Location: Eastern Shore, MD, USA
|
Do you have an example of where I need to do this at? I'm not the most expert PHP developer.
|
|
|
|
03-28-2009, 05:35 PM
|
Re: Captcha Problem!
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
In processor.php add the following after session_start()
PHP Code:
echo $_SESSION['security_code'] . '<br />';
echo $_POST['security_code'];
Post back with the output.
|
|
|
|
03-28-2009, 09:08 PM
|
Re: Captcha Problem!
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
Try this:
PHP Code:
<?php
//processor.php
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
session_start();
?>
Test Output: <br />
POST: <?php echo $_POST['security_code']; ?> <br />
SESSION: <?php echo $_SESSION['security_code']; ?> <br />
<?php
if( ($_SESSION['security_code']==$_POST['security_code']) && (!empty($_POST['security_code'])) ) {
mail("support@bkriegtech.net","Support Inquiry from Website","Form data:
Name: " . $_POST['field_1'] . "
E-Mail Address: " . $_POST['field_2'] . "
Username: " . $_POST['field_3'] . "
Problem Type: " . $_POST['field_4'] . "
Details: " . $_POST['field_5'] . "
.
");
include("confirm.html");
}
else {
echo "You have entered an invalid captcha string, please go back and try again.";
}
?>
|
|
|
|
03-28-2009, 09:19 PM
|
Re: Captcha Problem!
|
Posts: 286
Name: Adam
Location: Eastern Shore, MD, USA
|
Code:
Test Output:
POST:
SESSION: 9yvy6f
You have entered an invalid captcha string, please go back and try again.
Alright, well I get it now... not sure why it's not posting anything.
|
|
|
|
03-29-2009, 05:36 AM
|
Re: Captcha Problem!
|
Posts: 807
Name: Mattias Nordahl
Location: Sweden
|
I dont know if it makes any difference, but your missing some " in your <form> tag.
Have you tried to output the $_POST array, to see if any value is submitted or if it's just the security_code that's missing?
Try adding var_dump($_POST); in the same place as Nullpointer's test code.
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
|
|
|
|
03-29-2009, 01:24 PM
|
Re: Captcha Problem!
|
Posts: 286
Name: Adam
Location: Eastern Shore, MD, USA
|
Output:
Code:
Test Output:
Dump post: array(0) { }
POST:
SESSION: jrcycx
You have entered an invalid captcha string, please go back and try again.
Weird...
|
|
|
|
03-30-2009, 02:46 AM
|
Re: Captcha Problem!
|
Posts: 807
Name: Mattias Nordahl
Location: Sweden
|
Indeed. It's almost as if the form sends to another page, which in turn redirects to precessor.php, but the form looks correct... And the $_POST array isn't used anywhere else, so no other code is screwing with it. Odd.
It shouldn't matter, but have you tried with different browsers?
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
|
|
|
|
03-30-2009, 04:53 PM
|
Re: Captcha Problem!
|
Posts: 286
Name: Adam
Location: Eastern Shore, MD, USA
|
Yeah I tried FF3 and IE7, and IE8 when I upgraded to that last night. Same thing.
I have no idea what to do. Maybe someone has a decent script they can recommend for free? I just need it to do what www.bkriegtech.net/?page=contact does.
|
|
|
|
03-30-2009, 10:24 PM
|
Re: Captcha Problem!
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
There are a lot of CAPTCHAs out there. Personally, I use reCAPTCHA ( http://recaptcha.net/).
If you want to fix your current script, try validating your html to identify any problems with your form. From the code you posted it appears you are missing some quotes.
|
|
|
|
03-31-2009, 03:22 AM
|
Re: Captcha Problem!
|
Posts: 286
Name: Adam
Location: Eastern Shore, MD, USA
|
Quote:
Originally Posted by NullPointer
There are a lot of CAPTCHAs out there. Personally, I use reCAPTCHA ( http://recaptcha.net/).
If you want to fix your current script, try validating your html to identify any problems with your form. From the code you posted it appears you are missing some quotes.
|
Well HTML errors have nothing to do with this problem  it's something in my PHP but where, I have no idea.
|
|
|
|
04-05-2009, 08:50 AM
|
Re: Captcha Problem!
|
Posts: 4
Name: Philip Rollins
|
Well that just means your not passing it right use AJAX to send the XMLHttpRequest with a get/post function to carry the code to the next page then use javascript to restate the image. Of course I think this form is pass due date but owell.
|
|
|
|
|
« Reply to Captcha Problem!
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|