-2
private $api_url= "www.myurl.com";
  private $api_key = "111abjkbjkvsdf3879";

private function getpage($url, $redirect=FALSE) {
  $url = $this->purge_url($url);
  $ch = curl_init($url);
  curl_setopt($ch, CURLOPT_HEADER, 0);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
**/*Output the value of the array NULL NULL*/**
  $p_result = curl_exec($ch);
  $array = json_decode(trim($p_result), TRUE);
  var_dump($array);

  if ($redirect)  curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

 if (!$page=curl_exec($ch)) {
      $this->add_error("Remote GET connection to $url failed: ".curl_error($ch)); 
      curl_close($ch);
            return false;

  }
  curl_close($ch);

  $this->xmlsource = $page;

  return $page;
    } 

Output the value of the array in var_dump($array) is: NULL NULL Is the NULL in my case is the value or I did any mistake in my way to retrieve the value? I try to send APIkey request.

antrez770
  • 13
  • 8

1 Answers1

0

If what you get from var_export is actually an array with two values null then this corresponds to a successfull decode of the JSON [null, null].

See this example:

<?php
$encoded = "[null, null]";

$decoded = json_decode( $encoded, true );

var_export( $decoded );

outputs:

array (
  0 => NULL,
  1 => NULL,
)

If this is not what you expect then you need apply corrections to the GET request.

You can check it by inspecting $url that is passed to curl

If you want to inspect what the response actually is before decoding use var_export( $p_result );

Paolo
  • 15,233
  • 27
  • 70
  • 91
  • $p_result = curl_exec($ch); var_export( $p_result ); Receiving NULL NULL – antrez770 Jan 02 '18 at 08:52
  • `var_export` **cannot** output NULL NULL. Either it is the string `"NULL NULL"` or you're calling `var_export` twice in your code. Please be more specific. – Paolo Jan 02 '18 at 13:47
  • Would You know how can I check if the request is sent? Will do second file on same server and try to receive the request? And when I send the GET request with API KEY I will receive response from server, with another numbers, how can I save this going back link? – antrez770 Jan 02 '18 at 14:14
  • `curl_exec` returns `false` on failure so `if( $p_result === false ) { /* request failed / not sent */ }` – Paolo Jan 02 '18 at 14:22