Using reCAPTCHA on localhost

2020-01-25 03:16发布

I'm developing a website using PHP and I want to make a human verification in one of the sessions. For the development, I'm initially running the system locally and when it is ready, I'm gonna make put it on in a certain domain.

In the reCAPTCHA website it is said that the plugin will only work at the given domain (and subdomains).

My question is: Is there any way to use the reCAPTCHA plugin on a localhost?

17条回答
劫难
2楼-- · 2020-01-25 03:59

If you have old key, you should recreate your API Key. Also be aware of proxies.

查看更多
Anthone
3楼-- · 2020-01-25 04:00

Recaptcha will not work on localhost/

Use `127.0.0.1/` instead of `localhost/`
查看更多
乱世女痞
4楼-- · 2020-01-25 04:02

You can write "localhost" or "127.0.0.1" but URL must be the same

Example : Google Domains Add-> localhost URL => localhost/login.php

Example : Google Domains Add-> 127.0.0.1 URL => 127.0.0.1/login.php

查看更多
时光不老,我们不散
5楼-- · 2020-01-25 04:02

i got error related to recaptcha in laravel website, i resolved it by using some command and with env file and above answer will also help in this problem.

first of all check env file(in your case file which has google recaptcha key) for google recpatcha key.

second run these command :

  1. php artisan config:clear
  2. php artisan cache:clear
  3. composer dump-autoload
  4. php artisan view:clear
  5. php artisan route:clear

    it will solve your problem

查看更多
仙女界的扛把子
6楼-- · 2020-01-25 04:06

Update

The original answer is no longer correct. The developer's guide now states:

"If you would like to use "localhost" for development, you must add it to the list of domains."

This will only work if you access localhost using 127.0.0.1/... rather than localhost/....

The original answer is preserved below.


According to the reCAPTCHA Developer's Guide:

"localhost domains are no longer supported by default. If you wish to continue supporting them for development you can add them to the list of supported domains for your site key. Go to the admin console to update your list of supported domains. We advise to use a separate key for development and production and to not allow localhost on your production site key."

In other words, simply use the same key.

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2020-01-25 04:07

Yes, this an older question but this may be helping all the users having problems with reCaptcha on localhost. Google indeed says "By default, all keys work on 'localhost' (or '127.0.0.1')" but for real using reCaptcha on localhost may cause problems. In my case I solved mine using secure token

I posted a WORKING SOLUTION for PHP here

查看更多
登录 后发表回答