How to integrate google reCaptcha in PHP

google recaptcha integratein PHP, here are steps to follow:

<script src='' async defer ></script>
How to integrate google reCaptcha in PHP
How to integrate google reCaptcha in PHP

Create index.php file

	<script src='' async defer ></script>

	<form action="verify.php" method="post">
		<div class="g-recaptcha" data-sitekey="ENTER_SITE_KEY_HERE"></div>
		<input type="submit" name="submit" value="SUBMIT">

Add site key inside file and create new file call verify.php. you can use in any form eg. signup, signing, contact etc..

Read Also: How to generate captcha image in php

Create verify.php file

        $secret = 'SECRET_KEY_HERE';
        $verifyResponse = file_get_contents(''.$secret.'&response='.$_POST['g-recaptcha-response']);
        $responseData = json_decode($verifyResponse);
            $message = "Captcha varification successfully";
            $message = "Captcha varification fail.";
		echo $message;

It will generate response in JSON format you can decode it. return success or fail response.

Leave a Reply