Google Captcha not working

Hey

I followed these directions
https://developers.google.com/recaptcha/old/docs/php

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


<?php
require_once 'recaptchalib.php';
  require_once '../includes/functions.php';
  redirect_tablet_by($_SERVER['HTTP_USER_AGENT']);
  $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,
    $_SERVER["REMOTE_ADDR"],
    $_POST["recaptcha_challenge_field"],
    $_POST["recaptcha_response_field"]);

  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="https://maps.google.com/maps?f=q&amp;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="https://maps.google.com/maps?f=q&amp;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>
        </form>
        
    
<?php include "../includes/footer.php";

Open in new window

burnedfacelessAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

kenfcampCommented:
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.

Use

https://developers.google.com/recaptcha/docs/display
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Olaf DoschkeSoftware 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.
0
Buckminster GarciaCommented:
hope you are working in correct library  recaptchalib
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Google

From novice to tech pro — start learning today.