doulan4371 2019-01-18 16:55
浏览 229
已采纳

在PHP中使用ReCaptcha v2实现

So I have been having trouble implementing Recaptcha v2

Here is my form code

<form action="upload.php" method="POST" enctype="multipart/form-data">
<div id="html_element"></div>
<input type="file" name="file" style="font-family:'PSR';">
<button type="submit" name="submit">Upload</button>
<div class="g-recaptcha" data-sitekey="key" data-theme="dark"></div>

And this is the recaptcha part of code (same file but tried splitting into 2 before)

$secret = 'the secret';
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=". $secret."&response=".$_POST['g-recaptcha-response']."&remoteip=".$_SERVER['REMOTE_ADDR']);

$googleobj = json_decode($response);
echo $googleobj;
$verified = $googleobj->success;

if($verified === true)
      {

Whatever I do $verified always returns false. The echo part was me trying to debug but that has given me another error followed by a HTTP error 500.

PHP Recoverable fatal error:  Object of class stdClass could not be converted to string

Vardump of $_POST['g-recaptcha-response'] returns

string(334) "03AF6jDqXmI34YXuv1jIkgqHFo7TcjWbOq4-LJ_aTBRyzDld5BytgSe4ck_dolLm3C9CUzxela7LWa7hYJeJfEBONPPsx3ol7Ch-7SY8I9WyAFEy-iiGqwxZBY41gCSw7dfT42doqg-FIxwZweLOsH5YEf8i-L2QgkAJEd_PrWc9m2Uf6ZNbTDqCNr3VFqF8_0I-gS0Rhj9Z5XXwQLC9LeNfSWhI0DkpYNgK-hO4nGfEsaZT0PMlAg9DbHh9CzKDUzPpguVxz1zw0FP8CgwyBd9sgzpR4LfAoPuduGj0Z0wVcqbQ-CTifFtH7kCJuNG6bCDEufYfntj-8L"

Sorry if this is very basic stuff but im new to PHP

  • 写回答

2条回答 默认 最新

  • dongxieting9623 2019-01-18 17:02
    关注

    You are trying to echo an stdObject.

    $googleobj = json_decode($response);
    echo $googleobj;
    

    This does not work, because $googleobj is not a string, it's an object. When using the echo command, PHP tries to convert whatever is being echo'd into a string, which it cannot do with an object.

    Instead, you could do:

    $googleobj = json_decode($response);
    print_r($googleobj);
    

    Or simply remove the echo line completely.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 flask项目,怎么使用AJAX传数据库数据到echarts图表的data里,实现异步加载数据。
  • ¥15 本题的答案是不是有问题
  • ¥15 关于#r语言#的问题:(svydesign)为什么在一个大的数据集中抽取了一个小数据集
  • ¥15 C++使用Gunplot
  • ¥15 这个电路是如何实现路灯控制器的,原理是什么,怎么求解灯亮起后熄灭的时间如图?
  • ¥15 matlab数字图像处理频率域滤波
  • ¥15 在abaqus做了二维正交切削模型,给刀具添加了超声振动条件后输出切削力为什么比普通切削增大这么多
  • ¥15 ELGamal和paillier计算效率谁快?
  • ¥15 蓝桥杯单片机第十三届第一场,整点继电器吸合,5s后断开出现了问题
  • ¥15 file converter 转换格式失败 报错 Error marking filters as finished,如何解决?