integration Google No CAPTCHA reCAPTCHA using Laravel

integration Google No CAPTCHA reCAPTCHA using Laravel

Google reCaptcha in Laravel application Example

integration Google No CAPTCHA reCAPTCHA using Laravel Code – Setup Google Captcha PHP Nomally any simple Google captcha protect create we new websites from all the comments spamming.Google has recently new announced new service provided to prevent your website from menas fake spammers and malware attackers. It’s completely new reCAPTCHA API called fully check “Are you a Robot?”. and second one They named it “NO CAPTCHA reCAPTCHA”. It is designed to simple prevent we websites check from all the attackers and all the spammer.

Don’t forget to replace please <–Your Secret Key–> and with your own secret key.

Integrate simple Google reCAPTCHA into your Website

To integrate “Google reCAPTCHA” into your new website or web-apps you need to put simple Google check reCAPTCHA it in Client Side as well as in Server side. browser In Client HTML DOM images or sign page you need to simple integrate this all the line before tag.

Also Read :  Create Dynamic Image Slider using PHP with jQuery

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

Step1: pakainfo/no-captcha package installation

I will show you recommend Composer using cmd that is most widely used as a dependecy on the google manager for PHP simple packages. To add this plugin dependency using cmd – the command, run the following simple command from we project structure directory.

composer require pakainfo/no-captcha

Now simple add the service manager provider to the providers all the array list in following directory path config/app.php

config/app.php

pakainfo\NoCaptcha\NoCaptchaServiceProvider::class

Step2: simple Add and Get NOCAPTCHA_SECRET & NOCAPTCHA_SITEKEY

Add these changes line in we .env file in root directory path

NOCAPTCHA_SECRET=[your secret-key] - 6LeIxAcT7978989GG-vFI1TnR12548FuojJ4WifJWe
NOCAPTCHA_SITEKEY=[your site-key] - 6LeIxAcT898656596JcZVRqyHh71UMIEGN12356iZKhI

To get simple your secret-key and your site-key click here Recaptcha Admin

Also Read :  How to Get last inserted ID using Laravel

Step3: Add Route in this directory and Controller functions using laravel

Route::get('captcha-form-validation',array('as'=>'google.get-recaptcha-validation-form','uses'=>'FileController@livegetCapcha')) ;
Route::post('captcha-form-validation',array('as'=>'google.post-recaptcha-validation','uses'=>'FileController@mygetCapchaform')) ;

Add these simple two methods in we controller using laravel.

	
 public function livegetCapcha(){
	return view('files.captchaform');
 }
 public function mygetCapchaform(Request $request){
	 $this->validate($request, [
		  'name' => 'required',
		  'email'=>'required|email',
		  'mobile'=>'required|numeric|digits:10',
		  'comments' => 'required',
		  'g-recaptcha-response' => 'required|captcha',
	  ]);
 }

Step4: Add simple create a Blade File

Now create a simple blade file using cmd where you have to allowed validate we form using simple Google no-captcha recaptcha

resources/views/files/captchaform.blade.php

     <div class="panel panel-success">
        <div class="panel-heading">Simple Google reCaptcha Validation Example</div>
          <div class="panel-body">   
             <div class="row">
                    <div class="col-xs-6 col-sm-6 col-md-6 col-md-offset-3">
                {!! Form::open(array('route' => 'google.post-recaptcha-validation','method'=>'POST','files'=>true,'id'=>'liveform')) !!}
                 
                    <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group liveform">
                            <b>Name:</b>
                            {!! Form::text('name', null, array('placeholder' => 'Name','class' => 'form-control')) !!}
                            {!! $errors->first('name', '<p class="alert alert-success">:message</p>') !!}
                        </div>
                    </div>
                     <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group liveform">
                            <b>Email:</b>
                            {!! Form::text('email', null, array('placeholder' => 'Email','class' => 'form-control')) !!}
                            {!! $errors->first('email', '<p class="alert alert-success">:message</p>') !!}
                        </div>
                    </div>
                   <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group liveform">
                            <b>mobile:</b>
                            {!! Form::text('mobile', null, array('placeholder' => 'Mobile No','class' => 'form-control')) !!}
                            {!! $errors->first('mobile', '<p class="alert alert-success">:message</p>') !!}
                        </div>
                    </div>
                    <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group liveform">
                            <b>comments:</b>
                            {!! Form::textarea('comments', null, array('placeholder' => 'comments','class' => 'form-control','style'=>'height:100px')) !!}
                            {!! $errors->first('comments', '<p class="alert alert-success">:message</p>') !!}
                        </div>
                    </div>
                     <div class="col-xs-6 col-sm-6 col-md-6">
                        <div class="form-group liveform">
                            <b>Captcha:</b>
                            {!! app('captcha')->display() !!}
                            {!! $errors->first('g-recaptcha-response', '<p class="alert alert-success">:message</p>') !!}
                        </div>
                    </div>
                    <div class="col-xs-6 col-sm-6 col-md-6 text-center">
                            <button type="submit" class="btn btn-success">Submit</button>
                    </div>
              
                {!! Form::close() !!}
                </div>
               </div>
            </div>
        </div>

Don’t forget to add script file in head section.

Also Read :  javascript Manage cookies setcookie and getcookie

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

Leave a Reply

Your email address will not be published. Required fields are marked *