Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Captcha not displaying in GoDaddy secure (https)

I'm having an issue where Google's reCaptcha does not appear in my https website and was wondering if anyone else here has encountered/is encountering the same issue and has found a way around it.

In my test environment (localhost), it appears fine and I am able to send and receive the forms. However, upon uploading it to my GoDaddy hosted secure website, the reCaptcha image/div DOES NOT APPEAR and I haven't the slightest idea why.

Please help.

Below are parts of my code (that worked in localhost):

inside "head" tags

<script src='https://www.google.com/recaptcha/api.js'></script>

inside "body" where the recaptcha actually appears:

<div class="contact_text">
   <div class="g-recaptcha" id="googlecaptcha"
               data-sitekey="SITEKEYPLACEHOLDER"></div>
   <?php echo "<p class='text-danger col-xs-offset-6 col-xs-6'>$errCaptcha</p>";?>
</div>

then the "php" part:

$captcha = $_POST['g-recaptcha-response'];
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=SECRETKEYPLACEHOLDER&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
if($response.success==false){
    $errCaptcha = 'Please check captcha form';
}

I based it off of this tutorial https://codeforgeek.com/2014/12/google-recaptcha-tutorial/

To reiterate, the code/page/form works in my localhost test environment but DOESN'T SHOW when uploaded to my GoDaddy-hosted https website.

I appreciate any help or suggestions. Thank you.

Update:

Since I nor anyone has any leads on this topic, I opted to go for a different captcha called "secureimage" that adequately fulfilled my needs for now. I will keep this question open as I do really want to use Google's captcha because of the intuitive impressive checkbox style captcha.

Hopefully, someone in the near future finds a way.

Solution:

Removing the "https:" from the source path properly shows the Google reCaptcha!

<script src='//www.google.com/recaptcha/api.js'></script>

Code block and form now works. Thanks Matthew3k!

like image 925
publicknowledge Avatar asked Jun 19 '15 03:06

publicknowledge


1 Answers

Remove the "https:" from the source path.

<script src='//www.google.com/recaptcha/api.js'></script>

I have found this method to be successful for loading cross-domain resources on secure sites.

like image 79
Matthew3k Avatar answered Sep 20 '22 06:09

Matthew3k