Google Captcha not working


I followed these directions

And I have the code below. I"m always getting the message that says Google Captcha not working no matter what.

require_once 'recaptchalib.php';
  require_once '../includes/functions.php';
  $title = 'Contact Us';
  $description = 'Contact information and directions for Consolidated Utilities, Coastal Water and Sewage, Coastal Water Company, Whitemarsh Estates
    Water System, Woodlawn Water Savannah Ga, and Golden Isles Water System.';
  $privateKey = 'asdf';
  $errors = array();
  $flag = true;
  $name = null;
  $email = null;
  $address = null;
  $subject = null;
  $message = null;
  $alert = null;

$resp = recaptcha_check_answer ($privateKey,

  if (isset($_POST['submit'])) {
      if (isset($_POST['name'])) {
          $name = stripslashes($_POST['name']);
          $length = strlen($name);
          if ($length < 2 || $length > 40) {
              array_push($errors, 'Name must be between 2 and 40 characters.');
              $flag = false;
      } else {
          $name = null;
          array_push($errors, 'Name is a required field.');
          $flag = false;
      if (isset($_POST['email'])) {
          $email = stripslashes($_POST['email']);
          if (!filter_var($email, FILTER_VALIDATE_EMAIL )) {
              array_push($errors, 'Email address is invalid.');
              $flag = false;
      } else {
          $email = null;
          array_push($errors, 'An E-Mail Address is required.');
          $flag = false;
      if (isset($_POST['address'])) {
          $address = stripslashes($_POST['address']);
          $length = strlen($address);
          if ($length < 5 || $length > 120) {
              array_push($errors, 'Address must be between 5 and 120 characters.');
              $flag = false;
      } else {
          $address = null;
          array_push($errors, 'Address is a required field.');
          $flag = false;
      if (isset($_POST['subject'])) {
          $subject = stripslashes($_POST['subject']);
          $length = strlen($subject);
          if ($length < 2 || $length > 120) {
              array_push($errors, 'Subject length must be between 2 and 120 characters.');
              $flag = false;
      } else {
          $subject = null;
          array_push($errors, 'Subject is a required field.');
          $flag = false;
      if (isset($_POST['message'])) {
          $message = stripslashes($_POST['message']);
      } else {
          $message = null;
          array_push($errors, 'Message is a required field.');
          $flag = false;

      if (!$resp->is_valid) {
          array_push($errors, 'Google Captcha entered incorrectly.');
          $flag = false;

      if (!$flag) {
          $alert = '<div class="alert alert-danger"><ul>';
          foreach ($errors as $error) {
              $alert .= '<li>' . $error . '</li>';
          $alert .= '</ul></div>';
      } else {
          $alert = '<div class="alert alert-success">Thank you your message was received.</div>';

  include '../includes/header.php'; ?>
        <img src="../images/logo.jpg" height="120" width="196" id="logo" alt="logo">
        <h1 id="heading">Contact Us</h1><br/><br/><hr>
        <p><b>All emergencies must be called in.</b></p> 
        <p><b>Phone: </b><strong>(912) 233-3254</strong></p>
        <p><b>Fax: </b><strong>(912) 233-5654</strong></p>
        <p><address><strong>STREET ADDRESS:</strong> 119 W. Oglethorpe Ave. Savannah, GA 31401</address></p>
        <p><address><strong>MAILING ADDRESS:</strong> P.O. Box 9330 Savannah, GA 31412</address></p>
        <p> If you need directions there is an embeded map on this page. You can also visit this page from your smart phone or tablet for GPS directions.</p>
        <noscript>The embedded map will not display unless you enable JavaScript.</noscript>
        <iframe id="map" width="425" height="350" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" src=";source=s_q&amp;hl=en&amp;geocode=&amp;q=119+W+Oglethorpe+Ave,+Savannah,+GA&amp;aq=0&amp;oq=119+W.+Ogle&amp;sll=32.038844,-81.200278&amp;sspn=0.369026,0.517044&amp;ie=UTF8&amp;hq=&amp;hnear=119+W+Oglethorpe+Ave,+Savannah,+Georgia+31401&amp;t=m&amp;z=14&amp;ll=32.077248,-81.094522&amp;output=embed"></iframe><br /><small><a href=";source=embed&amp;hl=en&amp;geocode=&amp;q=119+W+Oglethorpe+Ave,+Savannah,+GA&amp;aq=0&amp;oq=119+W.+Ogle&amp;sll=32.038844,-81.200278&amp;sspn=0.369026,0.517044&amp;ie=UTF8&amp;hq=&amp;hnear=119+W+Oglethorpe+Ave,+Savannah,+Georgia+31401&amp;t=m&amp;z=14&amp;ll=32.077248,-81.094522" style="color:#0000FF;text-align:left">View Larger Map</a></small></div>
        <?php echo $alert; ?>
          <form name="contact" class="text-left" id="contact" method="post" action="index2.php">
	      <legend>Contact Us</legend>
		    <input type="text" id="name" name="name" placeholder="Name" value="<?php echo $name; ?>" required><br>
           <input type="email" id="email" name="email" placeholder="Email Address" value="<?php echo $email; ?>" required><br>
		    <input type="text" id="address" name="address" placeholder="Mailing Address" value="<?php echo $address; ?>" required><br>
	      <input type="text" id="subject" name="subject" placeholder="Subject" value="<?php echo $subject; ?>" required>
		    <legend>Enter your message below</legend>		
		    <textarea name="message" cols="40" rows="5"><?php echo $message;?></textarea><br/>
              <div class="g-recaptcha" data-sitekey="6LcuSTwUAAAAAGlSGCh_CmbyP676h_wjS3cw2cKi"></div>
            <button type="submit" name="submit" id="submit" class="btn btn-success"><i class="fa fa-check"></i> Send Message</button>
<?php include "../includes/footer.php";

Open in new window

Who is Participating?
kenfcampConnect With a Mentor Commented:
v1.0 is no longer supported

What happens to reCAPTCHA v1?

    Any calls to the v1 API will not work after March 31, 2018. Starting in November 2017, a percentage of reCAPTCHA v1 traffic will begin to show a notice informing users that the old API will soon be retired.

    Most websites around the world have already switched to reCAPTCHA v2, where humans pass effortlessly. With our advanced risk analysis engine, reCAPTCHA v2 can effectively separate humans from bots and always stay ahead of the attackers.

    If your site still uses reCAPTCHA v1, please upgrade to reCAPTCHA v2 immediately. We no longer support reCAPTCHA v1. Any calls to the v1 API will not work after March 31, 2018. Please register a new key and upgrade to v2.

Olaf DoschkeConnect With a Mentor Software DeveloperCommented:
Even if v1 would still work in most cases (at least it should up to march), I don't see you evaluating what the recaptcha_check_answer returns.
The instructions say you have to check $resp->is_valid.

Bye, Olaf.
Buckminster GarciaCommented:
hope you are working in correct library  recaptchalib
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.