at the end of this video tutorial you
will know how to protect your forms by
using Google recaptcha so stay with me
So now I'm
here at my PHPstorm and I have created
a new product I have also created one
empty index.php file and I have
started my localhost so if you didn't
start your own please do it also first
thing that you need to do in order to
protect your forms is to create that
fork and after that we will I will show
you how to protect so I will just create
a normal HTML document
I will create just one input the type
will be text and the placeholder will
be What is your name, this is just as an example
pain we are going to have one submit
button so the first thing that we need
to do to implement recaptcha is to go
to the google.com slash recaptcha and
after that we need to go to click on the
get reCAPTCHA
you shall not forward you wanna do
please do it
and now you will have the list of all
your recapture sites that you have been
using and since this is my test account
I don't have any I just have two that I
don't use it at all so first thing is we
need to create some label this is just
for you to remember where is your
which site for example for this one I will
say a local host tutorial I will to
recaptcha V2 and here I need to
input the list of the domains where I
will use this reCAPTCHA so at the moment
I will just use localhost I will click
on the accept reCAPTCHA Terms of Service and
I don't want any error and I will press
on register after that they will create
for us some site key secret key etc so
the first thing that we need to do
inside the HTML is we need to copy this
code and paste it just do before the
closing body tag the next thing that we
need to do is we need to copy this code
and paste it just before the closing
form tag like this and after that all we
need to do is to write the code that
will be on the server and that will
verify the CAPTCHA so I will say PHP and
I will say this is name of this button is
submit and I will write one if statement
where I will test if someone press this
save button and if he is
I will just accept all the informations
from the form so I have forget here name
let's say username so it will help username
equal post username we will have secret
key from here so our civics key is right
here so I will make sure to copy
everything sow secret key equal okay the
next thing that you need is response so
the value of our response is this we
need to copy this and we will say
response key equal post this and it is
optional to provide remote IP but I'm
going to show how to get user IP we can
get it back from the server remote
address and that's it and now the next thing
that we need to do is we will just send
to the Google secret key response key
and the user IP and on the Google they
will verify if someone is human actually
and they will return those informations
to the our so URL we will send those
information is here that's why by Google
we does need to copy and we will does
append secret key resposne key and user IP
to get method so we'll say secret
equal secret key
then we have resposne and removed IP
so response equal response key and
remote IP equal user IP and that not
will cow call the function file get
content and we will just provide the URL
to that function we could also write
this part here to here but I just don't
want to complicate things and now let's
see what will get us our response so if
we refresh you can see that we have got
one new HTML form that we have created
and also we have got the CAPTCHA from
the google so if the implant inside any
data here and press save as you
can see the goal will say success false
which means that our user didn't click
on this button and if we try to click
wait for them to verify and click on the
save as you can see we have got success
true which means the user is not robot
and it's human so as you can see here
the data is the JSON object and we
need to convert to the coded data so I
will say like this to response let's say
again equal JSON decode and now we will
have it as an object and we can say if
response success echo
else echo verification failed and now
let's test again so I'll say Senaid I get
save verification failed and now
if I try again and hit I'm not a robot
he'd say it is verification success your
name is Senaid so that is extremely easy
with us need to do some copy and paste
and if you guys have any questions
please let in the comments below and
also if you like this video please like
it and share with your friends
Take care
Không có nhận xét nào:
Đăng nhận xét