Fórum OpenCart Brasil

Por um e-commerce livre, confiável e profissional

Suporte geral sobre problemas técnicos para OpenCart v2.x.
#80763
Opencart 2.0.3.1 Tema Default.

Várias vezes ao dia aparece esse erro abaixo no log, referente ao recaptcha do google no formulário de contato. Eu nunca consegui reproduzir esse erro, então não sei como ocorre, suspeito que seja spam que não consegue resolver o desafio do google, pois o formulário funciona normalmente para clientes que realmente tenham dúvida e mandam mensagem.
Código: Selecionar todos
PHP Notice:  Undefined index: g-recaptcha-response in /home/admin/web/site/public_html/system/modification/catalog/controller/information/contact.php on line 237
A linha 237 tem o seguinte código:
Código: Selecionar todos
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $this->request->post['g-recaptcha-response'] . '&remoteip=' . $this->request->server['REMOTE_ADDR']);

			$recaptcha = json_decode($recaptcha, true);

			if (!$recaptcha['success']) {
				$this->error['captcha'] = $this->language->get('error_captcha');
			}
		}
Alguém sabe como resolver?
#80764
Olá @rlasmar.

Você está correto em sua suspeita, sem dúvidas é SPAM.

Para resolver o problema no arquivo:
catalog/controller/information/contact.php

Modifique a linha abaixo:
Código: Selecionar todos
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $this->request->post['g-recaptcha-response'] . '&remoteip=' . $this->request->server['REMOTE_ADDR']);

Pelas linhas abaixo:
Código: Selecionar todos
$g-recaptcha-response = (isset($this->request->post['g-recaptcha-response'])) ? $this->request->post['g-recaptcha-response'] : 'null';
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $g-recaptcha-response . '&remoteip=' . $this->request->server['REMOTE_ADDR']);

Salve as alterações no arquivo e atualize o cache de modificações.

Espero ter ajudado. :)
rlasmar gostou disso
#80772
Manoel Vidal escreveu:Fiz mais uma correção no código para resolver o problema. :D
Não deu certo ainda, continua o mesmo erro de syntax

Parse error: syntax error, unexpected '=' in /home/admin/web/site/public_html/system/modification/catalog/controller/information/contact.php on line 238
#80775
Manoel Vidal escreveu:Você adicionou novamente o código no arquivo?
Se sim, posteriormente atualizou novamente o cache de modificações?

Testei aqui e o erro citado não acontece. :)
Sim, limpei o cache.

Aqui está o código completo
Código: Selecionar todos
if ($this->config->get('config_google_captcha_status')) {
			$g-recaptcha-response = (isset($this->request->post['g-recaptcha-response'])) ? $this->request->post['g-recaptcha-response'] : 'null';
			$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $g-recaptcha-response . '&remoteip=' . $this->request->server['REMOTE_ADDR']);
			$recaptcha = json_decode($recaptcha, true);

			if (!$recaptcha['success']) {
				$this->error['captcha'] = $this->language->get('error_captcha');
			}
		}
#80782
Tem um erro no nome da variável "$g-recaptcha-response", deve substituir os hífens por underlines;

Substitua:
Código: Selecionar todos
$g-recaptcha-response = (isset($this->request->post['g-recaptcha-response'])) ? $this->request->post['g-recaptcha-response'] : 'null';
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $g-recaptcha-response . '&remoteip=' . $this->request->server['REMOTE_ADDR']);

Por:
Código: Selecionar todos
$g_recaptcha_response = (isset($this->request->post['g-recaptcha-response'])) ? $this->request->post['g-recaptcha-response'] : 'null';
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $g_recaptcha_response . '&remoteip=' . $this->request->server['REMOTE_ADDR']);
rlasmar gostou disso
#80789
Manoel Vidal escreveu:Como você está fazendo o teste?

Pois ao enviar o formulário de contato no OpenCart?

Não estou conseguindo replicar o erro que você mencionou depois da modificação no código.
Não chega nem a abrir a página de contato, já mostra o erro:
Parse error: syntax error, unexpected '=' in /home/admin/web/site/public_html/system/modification/catalog/controller/information/contact.php on line 238

Com o código do vetereno aparentemente deu certo, tinha que trocar o hifen por underline. Vou aguardar as próximas horas para ver se não ocorre mais erros quando há SPAM.
veteranodf escreveu:Tem um erro no nome da variável "$g-recaptcha-response", deve substituir os hífens por underlines;

Substitua:
Código: Selecionar todos
$g-recaptcha-response = (isset($this->request->post['g-recaptcha-response'])) ? $this->request->post['g-recaptcha-response'] : 'null';
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $g-recaptcha-response . '&remoteip=' . $this->request->server['REMOTE_ADDR']);

Por:
Código: Selecionar todos
$g_recaptcha_response = (isset($this->request->post['g-recaptcha-response'])) ? $this->request->post['g-recaptcha-response'] : 'null';
$recaptcha = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . urlencode($this->config->get('config_google_captcha_secret')) . '&response=' . $g_recaptcha_response . '&remoteip=' . $this->request->server['REMOTE_ADDR']);
Aparentemente deu certo, o erro de syntaxe sumiu, agora vou esperar alguns dias para ver se ocorre ainda erro com relação aos SPAM.

Looking for a partner for an unforgettable night? […]

Olá! Tudo bem? Verifique as configura&cced[…]

Olá! Tudo bem? Trabalho com Opencart h&aac[…]

Imagem do Carrinho de Compras

Olá! Tudo bem? São vários lo[…]