Jump to content

add Google recaptcha to contact form


lee_sov

Recommended Posts

So removing the IP key/value pair made no difference but dont need this anyway so might as well leave it out!

 

The output of the phpinfo is as below, - assume this means openssl is installed?

curl cURL support enabled cURL Information libcurl/7.20.0 OpenSSL/0.9.8q zlib/1.2.3

could this issue be something to do with the code in my contact.php?

script src="https://www.google.com/recaptcha/api.js" async defer></script>
			<form name="contact" action="submit.php" method="post">
			<fieldset class="conform">
			<legend>Your Details</legend><br />
			<label for="name">Name</label>
			<input id="name" type="text" size="40" value="<?php echo (isset($_POST["name"])) ? $_POST["name"] : '' ; ?>" name="name" /> <span class="red">**</span><br />
			<label for="company">Company</label>
			<input id="company" type="text" size="40" value="<?php  echo (isset($_POST["company"])) ? $_POST["company"] : '' ; ?>" name="company" /><br />
			<label for="telephone">Telephone</label>
			<input id="telephone" type="text" size="40" value="<?php echo  (isset($_POST["telephone"])) ? $_POST["telephone"] : ''; ?>" name="telephone" /><br />
			<label for="email">Email Address</label>
			<input id="email" type="text" size="40" value="<?php echo (isset($_POST["email"])) ? $_POST["email"] : ''; ?>" name="email" /> <span class="red">**</span><br />
			</fieldset>

			<fieldset class="conform2">

			<legend>Further Information</legend><br />
			<textarea id="comments" name="comments" size="40" rows="8" cols="50"><?php  echo(isset($_POST["comments"])) ? $_POST["comments"] : '' ; ?></textarea>
			</fieldset>
			<html>

  			<div class="g-recaptcha" data-sitekey="my key"></div><br>
  
			<br />
			<a href="javascript:document.contact.submit();"><img title="" height="43" alt="" src="images/submit.gif" width="102" border="0" /></a>
			</form>
			</div>

			<?php
				} else {
			?>
			<p>Thank you for your enquiry. We will reply as soon as possible.</p>
			<?php
				}
			?>
Link to comment
Share on other sites

Could you try this code... if I recall, curl 7.20.*, and 7.21.* has problems with CURLOPT_POST | CURLOPT_POSTFIELDS

 

if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
{
    if( isset ( $_POST['g-recaptcha-response'] ) && ! empty ( $_POST['g-recaptcha-response'] ) )
    {
        $key         = 'my key';

        $rip         = $_SERVER['REMOTE_ADDR'];

        $captchaurl  = 'https://www.google.com/recaptcha/api/siteverify?';

        $captchaurl .= 'secret=' . $key . '&';

        $captchaurl .= 'response=' . $_POST['g-recaptcha-response'] . '&';

        $captchaurl .= 'ip=' . $rip;

        $curl_init = curl_init ();

        curl_setopt ( $curl_init, CURLOPT_URL, $captchaurl );

        curl_setopt ( $curl_init, CURLOPT_RETURNTRANSFER, 1 );

        curl_setopt ( $curl_init, CURLOPT_TIMEOUT, 5 );

        curl_setopt ( $curl_init, CURLOPT_USERAGENT, 'PHP/reCAPTCHA' );

        curl_setopt ( $curl_init, CURLOPT_SSL_VERIFYPEER, FALSE );

        $response = curl_exec ( $curl_init );

        if ( $response == FALSE )
        {
            echo '<p>Curl Error: ' . curl_error ( $curl_init );
        }
        else
        {
            $result = json_decode ( $response, TRUE );

            echo 'Recaptha Result: ';

            var_dump ( $result['success'] );
        }

        curl_close ( $curl_init );
    }
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.