Avatar of burnedfaceless
burnedfaceless

asked on 

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

GooglePHP

Avatar of undefined
Last Comment
Buckminster Garcia

8/22/2022 - Mon