-1
Notice: Undefined index: captcha_code in /usr/www/users/bamboxevvz/recap2.php on line 51 The security code entered was incorrect.

Can someone help me?

Basically I'm trying to add a captcha to the form, it is called "Securimage"

Trying to implement it.

Here is the code:

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
session_start();
?>

<style>
#newheadform
{
    position: relative;
    top: -15px;
    left: 700px;
    width: 280px;
    height: 361px;
    border: 1px solid #<?php echo $Config['bodyFontColour']; ?>;
    background-color: #<?php echo $Config['bodyColour']; ?>;
    color: #<?php echo $Config['bodyFontColour']; ?>;
    opacity: 0.85;
    padding: 10px;
    z-index: 100;
    font-family: sans-serif;
}
#newheadform input[type=text], #newheadform textarea
{
    border: 1px solid #000;
    width: 96%;
}
</style>

<?php
include_once 'securimage/securimage.php';
$securimage = new Securimage();
?>


<!-- NEW ENQUIRY FORM START -->

                <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
                <table id="newheadform" cellpadding="5" cellspacing="0">
        <tr><th colspan="2" align="center"><font size="5">Email us now</font></th></tr>
        <tr><td>Name*:</td><td><input type="text" name="name"/></td></tr>
        <tr><td>Phone*:</td><td><input type="text" name="number"/></td></tr>
        <tr><td>Email*:</td><td><input type="text" name="email"/></td></tr>
        <tr><td colspan="2">Message:</td></tr>
        <tr><td colspan="2"><textarea name="message" style="height: 50px;"></textarea></td></tr>
        <tr><td colspan="2" align="center">
                <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">[Different Image]</a>

               <?php if($securimage->check($_POST['captcha_code']) == false) 
                           {
                echo "The security code entered was incorrect.<br /><br />";
                echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
               exit;
               }
               ?>
               <?php if(isset($_POST['number']))
        {
            if(empty($_POST['name']) || empty($_POST['number']) || empty($_POST['email']))
                echo '<font color="red" size="1"><b>* These fields are compulsory</b></font><br/><br/>';
            else
            {
                $headers='From: '.$_POST['email']."rn";
                $headers.='Reply-To: '.$_POST['email']."rn";
                $headers.='X-Mailer: PHP/'.phpversion();
                $body='You received a contact request from '.$_POST['name'].' ('.$_POST['email'].') on your site '.$domainname."rn";
                $body.='Contact number: '.$_POST['number']."rnrn";
                if(!empty($_POST['message'])) $body.=$_POST['message'];
                if(mail($_SESSION['contact3'],'New Enquiry from '.$domainname,$body,$headers))
                    echo '<font color="green"><b>Your email has been sent</b></font><br/>';
            }
        }
        else echo '<font size="1"><br>* Compulsory</br></font><br/><br/>'; ?>
        <input type="button" name="send" value="Send"/></td></tr>
</table>
</form>


<!-- NEW ENQUIRY FORM END -->
furas
  • 134,197
  • 12
  • 106
  • 148

1 Answers1

0

Change this

<?php if($securimage->check($_POST['captcha_code']) == false) 
                           {
                echo "The security code entered was incorrect.<br /><br />";
                echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
               exit;
               }
               ?>

to:

<?php 
    if(isset($_POST['captcha_code'])){
              if($securimage->check($_POST['captcha_code']) == false) 
                           {
                echo "The security code entered was incorrect.<br /><br />";
                echo "Please go <a href='javascript:history.go(-1)'>back</a> and try again.";
               exit;
               }
     }
               ?>

The problem is you need to check if the POST variable has been set before using it else that error will be thrown.

AyB
  • 11,609
  • 4
  • 32
  • 47