admin管理员组

文章数量:1122832

Need to read json data from a url. But it's has 3 login parameter. I've tried below but not working.

$username = "XXXXXXXX";
$password = "XXXXXXXX";
$client_id = "XXXXXXX";


$url = "1.php";

$context = stream_context_create(array(
    "http" => array(
        "header" => "Authorization: Basic " . base64_encode("$username:$password:$client_id")
    )));

$data = file_get_contents($url, false, $context);


echo $data;

What I'm doing wrong?

Need to read json data from a url. But it's has 3 login parameter. I've tried below but not working.

$username = "XXXXXXXX";
$password = "XXXXXXXX";
$client_id = "XXXXXXX";


$url = "1.php";

$context = stream_context_create(array(
    "http" => array(
        "header" => "Authorization: Basic " . base64_encode("$username:$password:$client_id")
    )));

$data = file_get_contents($url, false, $context);


echo $data;

What I'm doing wrong?

Share Improve this question asked yesterday Ripa SahaRipa Saha 2,5406 gold badges28 silver badges54 bronze badges 1
  • I don't like the authorization header generation. It should be just username:password. Carefully review the documentation of the API you want to use. – mr mcwolf Commented yesterday
Add a comment  | 

1 Answer 1

Reset to default 0

Pass client_id as a Query Parameter

$url = "1.php?client_id=" . urlencode($client_id);

$context = stream_context_create(array(
    "http" => array(
        "header" => "Authorization: Basic " . base64_encode("$username:$password")
    )));

$data = file_get_contents($url, false, $context);

echo $data;

Try this Hope it works!

本文标签: file get contentsfilegetcontents not working in json readStack Overflow