首页 > 解决方案 > 如何在php中获取对象的值?

问题描述

当我尝试获取对象值时遇到问题,其中没有任何内容。但是当我只是回显对象时,没有 null 我不知道如何获取该值

if(isset($_POST['submit'])) {

    $secret = "6Le3nvgUAAAAAMU0DRNLtvtaIq3h6X9ybEnO_txv";
    $captcha = $_POST['g-recaptcha-response'];
    $url = 'https://www.google.com/recaptcha/api/siteverify?secret='.$secret.'&response='.$captcha;

    $response = file_get_contents($url);


    echo $response;


}

我得到了回应

在此处输入图像描述

但是当我尝试 $response-> success 时。它返回 null ..

标签: phphtml

解决方案


您得到的响应是用 JavaScript Object Notation (JSON) 编写的。为此,PHP 获得了它自己的 JSON解码编码函数。

$decodedResponse = json_decode($response);
var_dump($decodedResponse->success);

推荐阅读