0

I am getting bool(false) when I var_dump $information I can access the API fine via the browser just not via the code below why?

    $json = file_get_contents('API URL');

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_URL, $json);  
    curl_setopt($ch, CURLOPT_USERPWD, "user:pw");
    curl_error($ch);
    $result = curl_exec($ch);
    curl_close($ch);

    $information = json_decode($result, true);

    var_dump($result);
6
  • what's the contents of the API file? Commented Nov 28, 2012 at 18:26
  • Have you check for errors with php.net/manual/en/function.curl-error.php? That would be the first thing to do. Commented Nov 28, 2012 at 18:26
  • What does var_dump($json) show? Commented Nov 28, 2012 at 18:27
  • @H2CO3 its a standard json api url file Commented Nov 28, 2012 at 18:28
  • @JessMcKenzie but what is its content? Commented Nov 28, 2012 at 18:28

1 Answer 1

3

This line

$json = file_get_contents('API URL');

should be

 $json = 'API_URL';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.