...

View Full Version : Installing Captcha. Small problem but can't seem to figure it out



crashgrad47
08-28-2011, 05:34 AM
I'm installing captcha on a contact form, and I've run into a small problem.

This is the coding I'm having trouble with:


<?php
session_start();
if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {

// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
unset($_SESSION['security_code']);
} else {

// Insert your code for showing an error message here
}
?>

Directions from the site on installing this code:
Place the following in the code where the form is submitted to. This code
will check what the user has typed matches the code in the image.

The page where the captcha is installed is letterphotography.net/contact.php
The confirmation page or email successful page is letterphotography.net/sendemail.php

I've been having problems installing the code and just don't know where to go from here. I'd appreciate the extra help. Thanks everyone

mlseim
08-28-2011, 04:41 PM
That snippet would go into the sendmail.php script.
But do you have some other validation in sendmail.php that will
send the user back if they enter something wrong?

It will be important to retain the text in the texboxes when you
send them back to re-enter a captcha code. So, we have to know
what you are already doing about "invalid" data.


.

tangoforce
08-28-2011, 05:01 PM
Thats just to check the captcha code entered is correct. The code you need to use to generate the actual captcha is a class from white hat web design (since removed from their website since their recent overhaul).

You need the actual class to generate the captcha image and set the session. White hat revamped their site recently and I've not seen it there again since so I've included a link to the article on the way back machine:
http://web.archive.org/web/20090501195745/http://www.white-hat-web-design.co.uk/articles/php-captcha.php

PS In future its useful to tell us what the problem actually is rather than leave us to guess :thumbsup:


Just found they've reinstated the article:
http://www.white-hat-web-design.co.uk/blog/php-captcha-security-images/

crashgrad47
08-28-2011, 06:56 PM
TangoForce, the captcha is installed. That's not the problem. However, the site that I was taking installation details from asks me to install the code I listed on the page where the form is submitted too.

I can't figure out where this snipped of code belongs.

Mlseim, I figured it belonged on the sendemail.php page, but where? I'm not too PHP savvy so I can't see where this code would fit in.

tangoforce
08-28-2011, 08:07 PM
It fits in around your code that you want to run if the captcha is correct. Did you not see the comments in the code?

In the area that has the comment:

// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.

THAT is where you put your normal code.

In the area that says

// Insert your code for showing an error message here
That is where you put your error code.

What is difficult about that? - You could use an include() in both areas instead if you prefer - eg include("sendmail.php");

What exactly is the problem you're having with inserting your code? Do you actually have any code to put there or is that what you want help with?

Of course if you show us the source from sendmail.php....

crashgrad47
08-28-2011, 09:06 PM
Tangoforce: Whoops! I did not realize you could not see the php code on sendemail.php. The reason I'm having difficulty is I'm not PHP savvy one bit, and when I tried doing it myself I got several error messages.

The code on the sendemail.php is this

<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do not try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - please enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was not submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - please fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = 'Letter Photography Customer Service Request';

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Senders Name: $visitor \n
Message: $notes \n
From: $visitor ($visitormail)\n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail ('sales@letterphotography.net', $subject, $message, $from);

?>


Now how should it look with the other code tied in?

Thanks for your help

tangoforce
08-28-2011, 09:13 PM
<?php
session_start();
if(($_SESSION['security_code'] == $_POST['security_code']) && (!empty($_SESSION['security_code'])) ) {

// Insert you code for processing the form here, e.g emailing the submission, entering it into a database.
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attn'];


if (eregi('http:', $notes)) {
die ("Do not try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - please enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was not submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}

if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - please fill in all fields</h2>\n";
die ("Use back! ! ");
}

$todayis = date("l, F j, Y, g:i a") ;

$attn = $attn ;
$subject = 'Letter Photography Customer Service Request';

$notes = stripcslashes($notes);

$message = " $todayis [EST] \n
Attention: $attn \n
Senders Name: $visitor \n
Message: $notes \n
From: $visitor ($visitormail)\n
Referral : $httpref \n
";

$from = "From: $visitormail\r\n";


mail ('sales@letterphotography.net', $subject, $message, $from);
unset($_SESSION['security_code']);
} else {

// Insert your code for showing an error message here
}
?>

Something like that :thumbsup:

tangoforce
08-28-2011, 09:14 PM
and when I tried doing it myself I got several error messages.

Always useful to show those but try the code above and let us know of any issues.

crashgrad47
08-29-2011, 12:17 AM
Thanks tangoforce, you've been a great help so far.

I copy and pasted the code you supplied. After I complete the contact form on contact.php, whether I get the captcha right or wrong, i get this message on the sendemail.php page:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at /home2/letterph/public_html/sendemail.php:12) in /home2/letterph/public_html/sendemail.php on line 93

Please note, I did not add code at either spots that requested it because I'm totally clueless as to what to add there.

tangoforce
08-29-2011, 12:39 AM
So its saying there is a problem on line 93.. I asked you to show the source from sendmail.php.. you posted what.. 20 - 30 lines?

Post the entire thing please. We can't solve errors on line 93 unless you show us what we're up against.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum