Forum Moderators: coopster
However it fails to recognise the code and keeps saying it's wrong, even though it's typed properly. I've include a "session_start" statement at the top which I believe is recommended as per their FAQs, but to no avail.
The form handler PHP is:
<?php session_start(); ?>
<?php error_reporting(E_ALL); ini_set('display_errors', 'on'); ?>
<?php
if($_POST['enquiryform'])
{
include_once $_SERVER['DOCUMENT_ROOT'] . '/send/securimage/securimage.php';
$securimage = new Securimage();
if ($securimage->check($_POST['captcha_code']) == false) {
// the code was incorrect
// handle the error accordingly with your other error checking
// or you can do something really basic like this
die('The code you entered was incorrect. Go back and try again.');
}
$mailto = "me@mydomain.com";
$mimebound = md5(uniqid(time()));
$subject = "Application from the Website";
$headers .="From: Website Application<applications@website.co.uk>\n";
$headers .="MIME-Version: 1.0\n";
$headers .="Content-Type: multipart/mixed; boundary=\"".$mimebound."\"\n\n";
$headers .="This is a multi-part message in MIME format.\n\n";
$message .="--".$mimebound."\n";
$message .="Content-type:text/plain; charset=iso-8859-1\n";
$message .="Content-Transfer-Encoding: 7bit\n";
$message .="Content-Disposition: inline\n\n";
$message .="Application from the website\n";
$message .="-----------------------------------------------\n\n";
$message .="Name: ".$_POST['_Name']."\n";
$message .="Address: ".$_POST['_Address']."\n";
$message .="Town: ".$_POST['_Town']."\n";
$message .="County: ".$_POST['_County']."\n";
$message .="Postcode: ".$_POST['_Postcode']."\n";
$message .="Telephone: ".$_POST['_Telephone']."\n";
$message .="Email: ".$_POST['_Email']."\n";
$message .="Grant Category: ".$_POST['_GrantCategory']."\n";
$message .="Name of course, or project proposal: ".$_POST['_NameOfCourse']."\n";
$message .="Duration of Course: ".$_POST['_Duration']."\n";
$message .="Brief statement in support of the application: ".$_POST['_Application']."\n";
$message .="Total Grant Requested: ".$_POST['_GrantRequested']."\n";
$message .="--\n\n";
if(mail($mailto,$subject,$message,$headers))
{
//print(nl2br($message));
header('location: [mywebsite...]
exit;
}
else
{
print('<b>Error</b>');
}
}
?>
Also the relevant code inside the form is this:
<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>
Anyone have any ideas, or if not- does anyone know of a good Captcha out there which is free and easy to configure?
You'd be better just trying a simple
if($success)
echo "Success"
else
echo "failure"
for the captcha, instead of posting 50+ lines of code.
Re:sessions - don't have to include this, I only use post and it works fine.
The following code (in the example you posted) could be causing the issue.
if($_POST['enquiryform'])
{
Also, I output the code the the captcha image as recommended in PHP :-
<img src="securimage.php?sid=<?php echo md5(uniqid(time())); ?>"><br /><br />
My check (which works)
if(!empty($_POST))
{
include("#*$!/securimage.php");
$img = new Securimage();
$valid = $img->check($_POST['code']);
if($valid == true) {
I've sorted the notice messages, however now getting a warning as follows:
Warning: Cannot modify header information - headers already sent by (output started at /sites/chadac/htdocs/submitform.php:4) in /sites/chadac/htdocs/submitform.php on line 57
Any ideas?
I've sorted the notice messages, however now getting a warning as follows:
Warning: Cannot modify header information - headers already sent by (output started at /sites/chadac/htdocs/submitform.php:4) in /sites/chadac/htdocs/submitform.php on line 57
Any ideas?
Warning: Cannot modify header information - headers already sent by
That error happens when there is some output sent to browser before you are calling the php header() function.
you have to call the header() function first thing before sending any echo or any html line to browser. look for any blank lines or any output lines before header() call