-2

i have a problem when i try to get the object value there's nothing in it. but when i just echo the object , there's no null i dont know how to get that value

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;


}

i got response

enter image description here

but when i try to $response-> success . it return null ..

1 Answers1

0

The response you 've got is written in JavaScript Object Notation (JSON). For this purpose PHP got it 's own JSON decode and encode functions.

$decodedResponse = json_decode($response);
var_dump($decodedResponse->success);
Marcel
  • 4,854
  • 1
  • 14
  • 24
  • wow great tyy . but the value now bool(true) , how to compare to $response == true ? 1 : 0 . – Alexsandro Siregar May 18 '20 at 08:18
  • You should definitely learn some PHP basics. Here you go: [If-conditions with PHP](https://www.php.net/manual/de/control-structures.if.php) and [how to dump the content of variables](https://www.php.net/manual/de/function.var-dump). I bet you 'll find out by yourself. – Marcel May 18 '20 at 08:31
  • i already find out bro. thanks – Alexsandro Siregar May 18 '20 at 13:15