Using CAPTCHA within Include files

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Using CAPTCHA within Include files

Post by simonmlewis »

I am building a support page using this:
http://www.phpcaptcha.org/documentation/quickstart/

I can get the script to work completely if I post the form result to a *.php page. However, if I post it to an include file, it fails.

From reading about it, it needs to run the session at the very start of the page, which thru an include file, obviously won't be.

Is there a way to run it on an include page?

This is the code on the page being posted to:

Code: Select all

<?php session_start(); 
include_once "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.');
}
else
{
echo "yes!!";}
?>

Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply