Search
 
SCRIPT & CODE EXAMPLE
 

PHP

how to add recaptcha validation in php

index.html

<html>
  <head>
    <title>Google recapcha demo - Codeforgeek</title>
    <script src='https://www.google.com/recaptcha/api.js'></script>
  </head>
  <body>
    <h1>Google reCAPTHA Demo</h1>
    <form id="comment_form" action="form.php" method="post">
      <input type="email" placeholder="Type your email" size="40"><br><br>
      <textarea name="comment" rows="8" cols="39"></textarea><br><br>
      <input type="submit" name="submit" value="Post comment"><br><br>
      <div class="g-recaptcha" data-sitekey="=== Your site key ==="></div>
    </form>
  </body>
</html>
verify.php

<?php
    $email; $comment; $captcha;

    if(isset($_POST['email']))
        $email=$_POST['email'];
    if(isset($_POST['comment']))
        $comment=$_POST['comment'];
    if(isset($_POST['g-recaptcha-response']))
        $captcha=$_POST['g-recaptcha-response'];

    if(!$captcha){
        echo '<h2>Please check the the captcha form.</h2>';
        exit;
    }

    $response = json_decode(file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=YOUR SECRET KEY&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']), true);
    if($response['success'] == false)
    {
        echo '<h2>You are spammer ! Get the @$%K out</h2>';
    }
    else
    {
        echo '<h2>Thanks for posting comment.</h2>';
    }
?>
Comment

PREVIOUS NEXT
Code Example
Php :: strval in php 
Php :: return last inserted id in laravel 
Php :: php foreach count rows 
Php :: laravel loop counter 
Php :: upload pdf file in laravel 
Php :: array_key_exists vs in_array 
Php :: laravel run seeder enter timestamps 
Php :: how add field to table by another migration in laravel 
Php :: how to use php echo data in javascript 
Php :: php sql get single value 
Php :: ajax post example php 
Php :: php mongodb version cmd 
Php :: php for loop array 
Php :: redirect back with input laravel in request 
Php :: php create an image 
Php :: wordpress add to cart redirect php 
Php :: get single column value in laravel eloquent 
Php :: delete all cookies in php 
Php :: laravel create seeder 
Php :: php run command line 
Php :: add hour minute in datetime in php 
Php :: woo set_stock_quantity 
Php :: change datetime format from Y-m-d h:i:s to d-m-Y in php 
Php :: laravel subtract date 
Php :: round up built in function php 
Php :: Exception::getMessage in php 
Php :: php cloudflare get country from IP 
Php :: php artisan migrate single file 
Php :: how to define function in php 
Php :: get static front page 
ADD CONTENT
Topic
Content
Source link
Name
1+8 =