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

有人可以幫我嗎?未定義的索引(CAPTCHA FORM)

基本上我試圖驗證碼添加到窗體,它被稱爲「Securimage」

試圖實現它。

下面是代碼:

<?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 --> 
+0

print_r($ _ POST);它顯示'captcha_code'? –

+0

是什麼?無論如何你是什麼意思Rohit – Pixel

+0

它的這一行 - > if($ securimage-> check($ _ POST ['captcha_code'])== false) – Pixel

回答

0

更改此

<?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['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; 
       } 
    } 
       ?> 

的問題是,你需要檢查POST變量使用前設置否則會引發錯誤。