表单提交时,Captcha Value不读取

I came across a problem with PHP form submission. I'm not able to read the captcha filed value in form submission. Here is the code

HTML

<div class="container">
   <h2 class="centertitle">Contact Us</h2>
   <div id="message"></div>
   <form method="post" action="php/contact.php" name="contactform" id="contactform">
      <div class="row">
          <div class="col-sm-3">
              <input type="text" name="name" placeholder="Name" id="name" class="form-control" />
          </div>
          <div class="col-sm-3">
              <input type="text" name="email" placeholder="Email" id="email" class="form-control" />
          </div>
          <div class="col-sm-3">
              <input type="text" name="phone" placeholder="Phone" id="phone" class="form-control" />
          </div>

          <div class="col-sm-3">
              <div id="captcha">
                <input type="text" name="verify" id="verify" class="form-control" placeholder="Enter Captcha" />
                <img src="php/image.php" alt="well, this is out capcha image" class="captcha" />
              </div>
          </div>
          </div>
          <div class="row">
            <div class="col-sm-12 text-center">
              <input type="submit" name="send" value="Submit" id="submit" class="sbtn" /> 
          </div>
       </div>
   </form>
</div><!-- /.container -->

Js Validation

$(document).ready(function() {
    //Form Validation
    $('#contactform').submit(function(){

      var action = $(this).attr('action');

      $("#message").slideUp(750,function() {
      $('#message').hide();

      $('#submit')
        //.after('<img src="images/ajax-loader.gif" class="loader" />')
        .attr('disabled','disabled');

      $.post(action, {
        name: $('#name').val(),
        email: $('#email').val(),
        phone: $('#phone').val(),
        subject: $('#subject').val(),
        comments: $('#comments').val(),
        verify: $('#verify').val()
      },
        function(data){
          document.getElementById('message').innerHTML = data;
          $('#message').slideDown('slow');
          $('#contactform img.loader').fadeOut('slow',function(){$(this).remove()});
          $('#submit').removeAttr('disabled');
          if(data.match('success') != null) $('#contactform').slideUp('slow');

        }
      );

      });

      return false;

    });
});

Contact.PHP

<?php

  if(!$_POST) exit;

   // Email address verification, do not edit.
   function isEmail($email) {
return(preg_match("/^[-_.[:alnum:]]+@((([[:alnum:]]|[[:alnum:]][[:alnum:]-]*[[:alnum:]])\.)+(ad|ae|aero|af|ag|ai|al|am|an|ao|aq|ar|arpa|as|at|au|aw|az|ba|bb|bd|be|bf|bg|bh|bi|biz|bj|bm|bn|bo|br|bs|bt|bv|bw|by|bz|ca|cc|cd|cf|cg|ch|ci|ck|cl|cm|cn|co|com|coop|cr|cs|cu|cv|cx|cy|cz|de|dj|dk|dm|do|dz|ec|edu|ee|eg|eh|er|es|et|eu|fi|fj|fk|fm|fo|fr|ga|gb|gd|ge|gf|gh|gi|gl|gm|gn|gov|gp|gq|gr|gs|gt|gu|gw|gy|hk|hm|hn|hr|ht|hu|id|ie|il|in|info|int|io|iq|ir|is|it|jm|jo|jp|ke|kg|kh|ki|km|kn|kp|kr|kw|ky|kz|la|lb|lc|li|lk|lr|ls|lt|lu|lv|ly|ma|mc|md|mg|mh|mil|mk|ml|mm|mn|mo|mp|mq|mr|ms|mt|mu|museum|mv|mw|mx|my|mz|na|name|nc|ne|net|nf|ng|ni|nl|no|np|nr|nt|nu|nz|om|org|pa|pe|pf|pg|ph|pk|pl|pm|pn|pr|pro|ps|pt|pw|py|qa|re|ro|ru|rw|sa|sb|sc|sd|se|sg|sh|si|sj|sk|sl|sm|sn|so|sr|st|su|sv|sy|sz|tc|td|tf|tg|th|tj|tk|tm|tn|to|tp|tr|tt|tv|tw|tz|ua|ug|uk|um|us|uy|uz|va|vc|ve|vg|vi|vn|vu|wf|ws|ye|yt|yu|za|zm|zw)$|(([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5])\.){3}([0-9][0-9]?|[0-1][0-9][0-9]|[2][0-4][0-9]|[2][5][0-5]))$/i",$email));
}
if (!defined("PHP_EOL")) define("PHP_EOL", "
");

$name     = $_POST['name'];
$email    = $_POST['email'];
$phone   = $_POST['phone'];
$verify   = $_POST['verify'];

if(trim($name) == '') {
    echo '<div class="error_message">Attention! You must enter your name.</div>';
    exit();
} else if(trim($email) == '') {
    echo '<div class="error_message">Attention! Please enter a valid email address.</div>';
    exit();
} else if(trim($phone) == '') {
    echo '<div class="error_message">Attention! Please enter a valid phone number.</div>';
exit();
} else if(!is_numeric($phone)) {
echo '<div class="error_message">Attention! Phone number can only contain digits.</div>';
    exit();
} else if(!isEmail($email)) {
    echo '<div class="error_message">Attention! You have entered an invalid e-mail address. Please try again.</div>';
    exit();
}

if(trim($verify) == '') {
    echo '<div class="error_message">Attention! Please Verify CAPTCHA.</div>';
    exit();
}else if(trim($verify) === $_SESSION["security_number"]) {

    echo '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
    exit();
}

if(get_magic_quotes_gpc()) {
    $comments = stripslashes($comments);
}


$address = "contact@sreejesh.in";


$e_subject = 'Form Submission.';


$e_body = "You have a new Form Submission." . PHP_EOL . PHP_EOL;
$e_content = "Name: $name,Phone: $phone,Email: $email" . PHP_EOL . PHP_EOL;
$e_reply = "";

$msg = wordwrap( $e_body . $e_content . $e_reply, 70 );

$headers = "From: $email" . PHP_EOL;
$headers .= "Reply-To: $email" . PHP_EOL;
$headers .= "MIME-Version: 1.0" . PHP_EOL;
$headers .= "Content-type: text/plain; charset=utf-8" . PHP_EOL;
$headers .= "Content-Transfer-Encoding: quoted-printable" . PHP_EOL;

if(mail($address, $e_subject, $msg, $headers)) {

    // Email has sent successfully, echo a success page.

    echo "<fieldset>";
    echo "<div id='success_page'>";
    echo "<h4>Email Sent Successfully.</h4>";
    echo "<p>Thank you <strong>$name</strong>, for your interest We will contact you shortly.</p>";
    echo "</div>";
    echo "</fieldset>";

} else {

    echo 'ERROR!';

}

For some reason I'm NOT getting value of $captcha It returns an error says** Currently the form get submitted without validation. For Captcha image I use this code -

Captcha Code(IMAGE.PHP)

<?php
session_start();    
$img=imagecreatefromjpeg("texture.jpg");    
$security_number = empty($_SESSION['security_number']) ? 'error' : $_SESSION['security_number'];
$image_text=$security_number;   

$red=rand(100,255); 
$green=rand(100,255);
$blue=rand(100,255);

$text_color=imagecolorallocate($img,255-$red,255-$green,255-$blue);

$text=imagettftext($img,16,rand(-10,10),rand(10,30),rand(25,35),$text_color,"fonts/courbd.ttf",$image_text);

header("Content-type:image/jpeg");
header("Content-Disposition:inline ; filename=secure.jpg"); 
imagejpeg($img);
?>

I'm a beginer in PHP & I'm sitting with this code for the last few hours. PLs help.

Here is a live URL - http://aisther.com/projects/sri/

If you want to use $_POST to read the form data, the form tag needs to look like

<form action='contact.php' method='post'>

Do not echo your session variable is it being created by your image.php script and exposing it to the user makes the captcha pointless.

HTML

<form action="contact.php" method="post">
  <div id="captcha">
    <img src="php/image.php" alt="well, this is out capcha image" class="captcha" />
    <input type="text" name="verify" id="verify" class="form-control" placeholder="Enter Captcha" />
  </div>
</form>

PHP

 session_start();
 if($_POST'verify'] == $_SESSION["security_number"]) {
      echo 'captcha matched';
 } else {
      echo 'bad captcha';
 }

Issue solved after adding session_start(); in contact.php

final code(contact.php)

 <?php

  session_start();

  *********************************************************

  $verify   = $_POST['verify'];
  $captcha = $_SESSION["security_number"];

  *********************************************************
  if(trim($verify) == '') {
    echo '<div class="error_message">Attention! Please Verify CAPTCHA.</div>';
    exit();
  }else if(trim($verify) != trim($captcha)) {
    echo  '<div class="error_message">Attention! The verification number you entered is incorrect.</div>';
    exit();
  }

  *********************************************************

?>