bonjour mon professeur m'a donné cette semaine le travail et je dois récupérer mes données JSON à partir d'une URL et l'afficher comme php en utilisant json_decode, le fichier php JSON qui i accéder avec l'url affiche les chansons comme un tableau json et fonctionne bien, et j'ai copié mon exemple curl enseignants pour accéder à l'url, mais il ne parvient pas à afficher quoi que ce soit que j'ai mal fait?php friser obtenir JSON et décode alors l'affichage, ne parvient affiche rien
Edit: je ne dois entrer un mot de passe et nom d'utilisateur pour accéder à l'URL alors j'ai changé le code comme dit, mais rien ne se affiche, j'ai changé le mot de passe et nom d'utilisateur pour la sécurité, mais le format et la longueur sont les mêmes
<?php
$username = "2foobar90";
$password = "123456";
// Initialise the cURL connection
$connection = curl_init();
curl_setopt($connection, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($connection, CURLOPT_USERPWD, $username . ":" . $password);
// Specify the URL to connect to - DOUBLE CLICK link to test
curl_setopt($connection, CURLOPT_URL, "https://edward2.solent.ac.uk/~martine/year3/hits.php?artist=David+Bowie");
// This option ensures that the HTTP response is *returned* from curl_exec(),
// (see below) rather than being output to screen.
curl_setopt($connection,CURLOPT_RETURNTRANSFER,1);
// Do not include the HTTP header in the response.
curl_setopt($connection,CURLOPT_HEADER, 0);
// Actually connect to the remote URL. The response is
// returned from curl_exec() and placed in $response.
$response = curl_exec($connection);
// Close the connection.
curl_close($connection);
$data = json_decode($response, true);
for($i=0; $i<count($data); $i++)
{
echo "Song id " . $data[$i]["songid"] . " " .
"Title " . $data[$i]["title"] . " " .
"Artist " . $data[$i]["artist"] . " " .
"Chart position " . $data[$i]["chart"] . "<br/>";
}
?>
Juste comme une note les deux fichiers sont sur le même serveur, dans le même dossier. –