...

View Full Version : error check in code



jewelsmac66
02-17-2010, 09:30 PM
Hi all,

I have an HTML form and the PHP that it calls on. I added a Captcha/Securimage to my form to prevent spamming and I am still having problems. I have read through several forums and tried editing my PHP a thousand different ways, but it either gives me a different error every time or it does go through to the thank you message WITHOUT sending the form's info to my inbox like it used to.

The HTML part is working just fine, it refreshes the image and does what it's supposed to do. The problem is just getting it all to verify that all the form info AND the security code are BOTH correct in order to send the form to my inbox.

I feel like I am so close with this code, but just cant figure out whats wrong. Please help if you can! Thank you!!

The current error message I'm getting is:
Parse error: syntax error, unexpected T_ELSE in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 106
***If i do delete the ELSE from the code, then I get an error saying an unexpected } occurred, so i do that and get another error, and it goes on and on in a circle like this***

Here is the part of the code from the HTML form that uses the securimage:
<tr>
<td>&nbsp;</td>
<td><img id="captcha" src="../securimage/securimage_show.php" alt="CAPTCHA Image" />
<input type="text" name="captcha_code" size="10" maxlength="6" />
<a href="#" onClick="document.getElementById('captcha').src = '../securimage/securimage_show.php?' + Math.random(); return false">Reload Image</a>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td align="right"><input name="Reset" type="reset" value="Reset"></td>
<td><p><input type="submit" name="Submit" value="Submit"></p></td>
</tr>
</table>

</form>

</body>
</html>


Here is the PHP the form calls on:


<?php session_start();
?>

<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

// we'll begin by assigning the To address and message subject
$to="jmacdesigns@gmail.com";
$subject="E-mail with attachment";

// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";

// here, we'll start the message body. all entries ARE case sensitive!!
// this is the text that will be displayed
// in the e-mail
$message = $_POST['message'];

$YourName = $_POST['YourName'];
$BizName = $_POST['BizName'];
$address = $_POST['address'];
$city = $_POST['city'];
$State = $_POST['State'];
$zipcode = $_POST['zipcode'];
$email = $_POST['email'];
$JobType = $_POST['JobType'];
$JobDimensions = $_POST['JobDimensions'];
$Quantity = $_POST['Quantity'];
$PaperWhite = $_POST['PaperWhite'];
$PaperOffWhite = $_POST['PaperOffWhite'];
$PaperCSWhite = $_POST['PaperCSWhite'];
$PaperCSOffWhite = $_POST['PaperCSOffWhite'];
$PaperOther = $_POST['PaperOther'];
$LaminationYes = $_POST['LaminationYes'];
$LaminationNo = $_POST['LaminationNo'];
$DateReq = $_POST['DateReq'];
$comments = $_POST['comments'];

$message= "Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

// next, we'll build the invisible portion of the message body
// note that we insert two dashes in front of the MIME boundary
// when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
}
// now we'll process our uploaded files
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];

// if the upload succeded, the file will exist
if (file_exists($tmp_name)){

// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){

// open the file for a binary read
$file = fopen($tmp_name,'rb');

// read the file content into a variable
$data = fread($file,filesize($tmp_name));

// close the file
fclose($file);

// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}

// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content.
// NOTE: we don't set another boundary to indicate that the end of the
// file has been reached here. we only want one boundary between each file
// we'll add the final one after the loop finishes.
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
// here's our closing mime boundary that indicates the last of the message
$message.="--{$mime_boundary}--\n";

//form is posted
else { //form is posted
include("securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);

// now we just send the message
// formhandler2.php
if ( sizeof($_POST) > 1 . $valid == true) {
// process & validate form

// if all data is present and "clean", then proceed
if ( mail($to, $subject, $message, $headers) ) {
// mail success!
header("Location: thankyou.html");
} else {
// mail failure!
header("Location: tryagain.html");
}
}

?>

DaiWelsh
02-17-2010, 09:34 PM
if ( sizeof($_POST) > 1 . $valid == true) {

Not checked the file line bbut I suspect this is the problem line. Hard to be sure what it is supposed to be but maybe


if (( sizeof($_POST) > 1) and ($valid == true)) {

at a guess?

HTH,

Dai

jewelsmac66
02-17-2010, 10:01 PM
Hi and thanks for the suggestion. I tried it your way and I am still getting the same error. How can I correct the code for the securimage stuff? I think its something in there thats not written right...?

Parse error: syntax error, unexpected T_ELSE in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 106

Line 106 starts like this, underneath "//form is posted":
else { //form is posted
include("securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);

Fou-Lu
02-17-2010, 10:10 PM
}
// here's our closing mime boundary that indicates the last of the message
$message.="--{$mime_boundary}--\n";

//form is posted
else { //form is posted
include("securimage.php");
$img = new Securimage();


You got a little something or other there between you're if and else blocks ;)
That $message appending has to go somewhere else.

jewelsmac66
02-17-2010, 10:15 PM
I'm sorry, but i don't understand your correction. :confused:
There is nothing in there about the $message or the securimage stuff.
Where do I move the $message part to? Is the ELSE block with the securimage lines written correctly? Does that stay where it is?
Sorry!

Dormilich
02-17-2010, 10:20 PM
yupp, just before that is an ordinary code line, but an else statement requires an if statement immediately before it.


// invalid
if (condition) {
// some code
}
doSomething();
else {
// some code
}

// correct
if (condition) {
// some code
}
else {
// some code
}

jewelsmac66
02-18-2010, 02:22 PM
Sorry for not being able to reply last night... my wireless keyboard died, of course, and then I had to leave for the day. I hope you're still out there and can help me...!

Thanks for explaining the IF and ELSE formatting. I think that makes more sense to me now as to what I was missing. So my question is, since I already have the "checker" in place to either send you to the thankyou.html if valid, or the tryagain.html if invalid, how do I add the additional element of checking to see if the securimage info was entered correctly?

I tried to do this myself by implementing your correct formatting and also follow the instructions from the original source (http://www.phpcaptcha.org/documentation/quickstart/) and I am getting this error, which I have also gotten before in other attempts:

Fatal error: Call to a member function check() on a non-object in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 108

Here is the PHP code I just used which gave me that error message (if you need it, my HTML form code that calls on this PHP is in my original post) :


<?php session_start();
?>

<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

// we'll begin by assigning the To address and message subject
$to="jmacdesigns@gmail.com";
$subject="E-mail with attachment";

// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";

// here, we'll start the message body. all entries ARE case sensitive!!
// this is the text that will be displayed
// in the e-mail
$message = $_POST['message'];

$YourName = $_POST['YourName'];
$BizName = $_POST['BizName'];
$address = $_POST['address'];
$city = $_POST['city'];
$State = $_POST['State'];
$zipcode = $_POST['zipcode'];
$email = $_POST['email'];
$JobType = $_POST['JobType'];
$JobDimensions = $_POST['JobDimensions'];
$Quantity = $_POST['Quantity'];
$PaperWhite = $_POST['PaperWhite'];
$PaperOffWhite = $_POST['PaperOffWhite'];
$PaperCSWhite = $_POST['PaperCSWhite'];
$PaperCSOffWhite = $_POST['PaperCSOffWhite'];
$PaperOther = $_POST['PaperOther'];
$LaminationYes = $_POST['LaminationYes'];
$LaminationNo = $_POST['LaminationNo'];
$DateReq = $_POST['DateReq'];
$comments = $_POST['comments'];

$message= "Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

// next, we'll build the invisible portion of the message body
// note that we insert two dashes in front of the MIME boundary
// when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
}
// now we'll process our uploaded files
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];

// if the upload succeded, the file will exist
if (file_exists($tmp_name)){

// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){

// open the file for a binary read
$file = fopen($tmp_name,'rb');

// read the file content into a variable
$data = fread($file,filesize($tmp_name));

// close the file
fclose($file);

// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}

// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content.
// NOTE: we don't set another boundary to indicate that the end of the
// file has been reached here. we only want one boundary between each file
// we'll add the final one after the loop finishes.
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
// here's our closing mime boundary that indicates the last of the message
$message.="--{$mime_boundary}--\n";

//securimage code at http://www.phpcaptcha.org/documentation/quickstart/
include_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new Securimage();
$valid = $img->check($_POST['code']);
//Next we will actually check to see if the code was correct.
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking
}

// now we just send the message
// formhandler2.php
if (( sizeof($_POST) > 1) and ($valid == true)) {
// process & validate form

// if all data is present and "clean", then proceed
if ( mail($to, $subject, $message, $headers) ) {
// mail success!
header("Location: thankyou.html");
} else {
// mail failure!
header("Location: tryagain.html");
}
}

?>

Fou-Lu
02-18-2010, 02:32 PM
This one should be a simple fix (but I'm not sure what you want to do with it):


$securimage = new Securimage();
$valid = $img->check($_POST['code']);

$img is not an object, chances are that second line there should be $valid = $securimage->check($_POST['code']);, but I cannot be 100% certain since I've never used a prebuilt captcha before.

BTW, this one is more work than you need (though it is technically more accurate, since you're checking for true):


if (( sizeof($_POST) > 1) and ($valid == true)) {

The same could be written as


if (sizeof($_POST) > 1 && $valid) { // Or count($_POST)

Dormilich
02-18-2010, 02:33 PM
and another perspective …


require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
to see if the file was actually loaded. (though I agree with Fou-Lu about the $img.)

Fou-Lu
02-18-2010, 02:37 PM
and another perspective …


require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
to see if the file was actually loaded. (though I agree with Fou-Lu about the $img.)

It won't be a problem with the inclusion. If it failed, the require will trigger a fatal error. What is possible is that the file itself is incorrect, but then it would complain about how it cannot find the definition for the class SecurImage when instatiating it rather than when trying to call on the non-object.

Dormilich
02-18-2010, 02:39 PM
It won't be a problem with the inclusion. If it failed, the require will trigger a fatal error.
exactly, if the fatal error doesn’t come up, you can be sure the file is at least loaded.

jewelsmac66
02-18-2010, 03:07 PM
Thank you all for your feedback. I tried your corrections and am getting the same error as before:

Fatal error: Call to a member function check() on a non-object in /home/content/j/e/w/jewelsmac6/html/formhandler2.php on line 107

Do you know what this check() thing is that it is asking for?



<?php session_start();
?>

<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

// we'll begin by assigning the To address and message subject
$to="jmacdesigns@gmail.com";
$subject="E-mail with attachment";

// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";

// here, we'll start the message body. all entries ARE case sensitive!!
// this is the text that will be displayed
// in the e-mail
$message = $_POST['message'];

$YourName = $_POST['YourName'];
$BizName = $_POST['BizName'];
$address = $_POST['address'];
$city = $_POST['city'];
$State = $_POST['State'];
$zipcode = $_POST['zipcode'];
$email = $_POST['email'];
$JobType = $_POST['JobType'];
$JobDimensions = $_POST['JobDimensions'];
$Quantity = $_POST['Quantity'];
$PaperWhite = $_POST['PaperWhite'];
$PaperOffWhite = $_POST['PaperOffWhite'];
$PaperCSWhite = $_POST['PaperCSWhite'];
$PaperCSOffWhite = $_POST['PaperCSOffWhite'];
$PaperOther = $_POST['PaperOther'];
$LaminationYes = $_POST['LaminationYes'];
$LaminationNo = $_POST['LaminationNo'];
$DateReq = $_POST['DateReq'];
$comments = $_POST['comments'];

$message= "Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

// next, we'll build the invisible portion of the message body
// note that we insert two dashes in front of the MIME boundary
// when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
}
// now we'll process our uploaded files
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];

// if the upload succeded, the file will exist
if (file_exists($tmp_name)){

// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){

// open the file for a binary read
$file = fopen($tmp_name,'rb');

// read the file content into a variable
$data = fread($file,filesize($tmp_name));

// close the file
fclose($file);

// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}

// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content.
// NOTE: we don't set another boundary to indicate that the end of the
// file has been reached here. we only want one boundary between each file
// we'll add the final one after the loop finishes.
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
// here's our closing mime boundary that indicates the last of the message
$message.="--{$mime_boundary}--\n";

//LINE 105, securimage code at http://www.phpcaptcha.org/documentation/quickstart/
require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$valid = $securimage->check($_POST['code']); //THIS IS LINE 107
//Next we will actually check to see if the code was correct.
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking
}

// now we just send the message
// formhandler2.php
if (( sizeof($_POST) > 1) and ($valid == true)) {
// process & validate form

// if all data is present and "clean", then proceed
if ( mail($to, $subject, $message, $headers) ) {
// mail success!
header("Location: thankyou.html");
} else {
// mail failure!
header("Location: tryagain.html");
}
}

?>

Dormilich
02-18-2010, 03:34 PM
you forgot to create the Secureimage object.

jewelsmac66
02-18-2010, 03:51 PM
Shoot! I inserted the line and now the form goes to an empty white webpage. I assume this means it all checked out correctly, however, the form's info and file attachment never came in to my inbox either.

I have the $valid added into the line where it goes to send the message, but it did not deliver or redirect.



<?php session_start();
?>

<?php
if ($_SERVER['REQUEST_METHOD']=="POST"){

// we'll begin by assigning the To address and message subject
$to="jmacdesigns@gmail.com";
$subject="E-mail with attachment";

// get the sender's name and email address
// we'll just plug them a variable to be used later
$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";

// generate a random string to be used as the boundary marker
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";

// now we'll build the message headers
$headers = "From: $from\r\n" .
"MIME-Version: 1.0\r\n" .
"Content-Type: multipart/mixed;\r\n" .
" boundary=\"{$mime_boundary}\"";

// here, we'll start the message body. all entries ARE case sensitive!!
// this is the text that will be displayed
// in the e-mail
$message = $_POST['message'];

$YourName = $_POST['YourName'];
$BizName = $_POST['BizName'];
$address = $_POST['address'];
$city = $_POST['city'];
$State = $_POST['State'];
$zipcode = $_POST['zipcode'];
$email = $_POST['email'];
$JobType = $_POST['JobType'];
$JobDimensions = $_POST['JobDimensions'];
$Quantity = $_POST['Quantity'];
$PaperWhite = $_POST['PaperWhite'];
$PaperOffWhite = $_POST['PaperOffWhite'];
$PaperCSWhite = $_POST['PaperCSWhite'];
$PaperCSOffWhite = $_POST['PaperCSOffWhite'];
$PaperOther = $_POST['PaperOther'];
$LaminationYes = $_POST['LaminationYes'];
$LaminationNo = $_POST['LaminationNo'];
$DateReq = $_POST['DateReq'];
$comments = $_POST['comments'];

$message= "Your Name: $YourName\n\nBusiness Name: $BizName\n\nAddress: $Address\n\nCity: $City\n\nState: $State\n\nZip Code: $ZipCode\n\nEmail: $email\n\nJob Type: $JobType\n\nJob Dimensions: $JobDimensions\n\nQuantity: $Quantity\n\nPaper White: $PaperWhite\n\nPaper Off White: $PaperOffWhite\n\nPaper Card Stock White: $PaperCSWhite\n\nPaper Card Stock Off White: $PaperCSOffWhite\n\nPaper Other: $PaperOther\n\nLamination Yes: $LaminationYes\n\nLamination No: $LaminationNo\n\nDate Required: $DateReq\n\nComments: $comments\n\n";

// next, we'll build the invisible portion of the message body
// note that we insert two dashes in front of the MIME boundary
// when we use it
$message = "This is a multi-part message in MIME format.\n\n" .
"--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message . "\n\n";
}
// now we'll process our uploaded files
foreach($_FILES as $userfile){
// store the file information to variables for easier access
$tmp_name = $userfile['tmp_name'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];

// if the upload succeded, the file will exist
if (file_exists($tmp_name)){

// check to make sure that it is an uploaded file and not a system file
if(is_uploaded_file($tmp_name)){

// open the file for a binary read
$file = fopen($tmp_name,'rb');

// read the file content into a variable
$data = fread($file,filesize($tmp_name));

// close the file
fclose($file);

// now we encode it and split it into acceptable length lines
$data = chunk_split(base64_encode($data));
}

// now we'll insert a boundary to indicate we're starting the attachment
// we have to specify the content type, file name, and disposition as
// an attachment, then add the file content.
// NOTE: we don't set another boundary to indicate that the end of the
// file has been reached here. we only want one boundary between each file
// we'll add the final one after the loop finishes.
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$type};\n" .
" name=\"{$name}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n";
}
}
// here's our closing mime boundary that indicates the last of the message
$message.="--{$mime_boundary}--\n";

//LINE 105, securimage code at http://www.phpcaptcha.org/documentation/quickstart/
require_once $_SERVER['DOCUMENT_ROOT'] . '/securimage/securimage.php';
$securimage = new securimage();
$valid = $securimage->check($_POST['code']); //THIS IS LINE 108
//Next we will actually check to see if the code was correct.
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking
}

// now we just send the message
// formhandler2.php
if (( sizeof($_POST) > 1) and ($valid == true)) {
// process & validate form

// if all data is present and "clean", then proceed
if ( mail($to, $subject, $message, $headers) ) {
// mail success!
header("Location: thankyou.html");
} else {
// mail failure!
header("Location: tryagain.html");
}
}

?>

Dormilich
02-18-2010, 07:07 PM
if you’re neither at thankyou.html nor tryagain.html, then my guess is, that the captcha is not valid (the only flow, where you don’t end up at a website)

jewelsmac66
02-18-2010, 08:00 PM
That really stinks if this means its not valid. :mad:

I got the code and all the stuff from http://www.phpcaptcha.org. I then uploaded the entire folder to my site in order to direct the capthca code on my PHP form to that folder. The example_form.php that came with the files works fine, but when i go to copy/paste their code into my PHP, i have the problems. Should I look into getting another captcha code? Any recommendations?

Or maybe I missed something in their PHP code when I pasted it into my PHP?

Here is the link to their example form page that i uploaded to my site and the code to go with it:

http://jewelsdesignworks.com/securimage/example_form.php



<?php

/**
* Project: Securimage: A PHP class for creating and managing form CAPTCHA images<br />
* File: securimage.php<br />
* URL: www.phpcaptcha.org
*/


session_start(); // Start the session where the code will be stored.

?>
<html>
<head>
<title>Securimage Test Form</title>
</head>

<body>

<?php
if (empty($_POST)) { ?>
<form method="POST">
Username:<br />
<input type="text" name="username" /><br />
Password:<br />
<input type="text" name="password" /><br /><br />

<div style="width: 430px; float: left; height: 90px">
<img id="siimage" align="left" style="padding-right: 5px; border: 0" src="securimage_show.php?sid=<?php echo md5(time()) ?>" />

<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="19" height="19" id="SecurImage_as3" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="securimage_play.swf?audio=securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" />
<param name="quality" value="high" />

<param name="bgcolor" value="#ffffff" />
<embed src="securimage_play.swf?audio=securimage_play.php&bgColor1=#777&bgColor2=#fff&iconColor=#000&roundedCorner=5" quality="high" bgcolor="#ffffff" width="19" height="19" name="SecurImage_as3" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

<br />

<!-- pass a session id to the query string of the script to prevent ie caching -->
<a tabindex="-1" style="border-style: none" href="#" title="Refresh Image" onClick="document.getElementById('siimage').src = 'securimage_show.php?sid=' + Math.random(); return false"><img src="images/refresh.gif" alt="Reload Image" border="0" onClick="this.blur()" align="bottom" /></a>
</div>
<div style="clear: both"></div>
Code:<br />

<!-- NOTE: the "name" attribute is "code" so that $img->check($_POST['code']) will check the submitted form field -->
<input type="text" name="code" size="12" /><br /><br />

<input type="submit" value="Submit Form" />
</form>

<?php
} else { //form is posted
include("securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);

if($valid == true) {
echo "<center>Thanks, you entered the correct code.<br />Click <a href=\"{$_SERVER['PHP_SELF']}\">here</a> to go back.</center>";
} else {
echo "<center>Sorry, the code you entered was invalid. <a href=\"javascript:history.go(-1)\">Go back</a> to try again.</center>";
}
}

?>

</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum