API を使用して、フォームに入力したユーザーが入力した単語をウィキペディアで検索しようとしています。そのため、フォームに「cat」と入力すると、API はウィキペディアで「cat」という単語を含むエントリを検索します。 "。動作するようになりましたが、次のメッセージが表示されます。
Warning: file_get_contents(http://en.wikipedia.org/w/api.php?action=opensearch&search=parrott): failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden in /var/www/html/flam1-api.php on line 22
おそらくユーザーエージェントが必要だと読んだのですが、正確に何をすべきかわかりません。これが私のコードです:
echo "<h1>Which LOLcat are you? Results!</h1>";
$visit_id = $_COOKIE['visit_id'];
$all_my_variables = json_decode(file_get_contents("/var/www/html/data/$visit_id.json"));
//var_dump($all_my_variables);
$animal = $all_my_variables ->favoriteanimal;
echo "When searching wikipedia entries on your favorite animal, which is a $animal, we got the results:<br>";
$website = file_get_contents('http://en.wikipedia.org/w/api.php?action=opensearch&search='.urlencode($animal).'');
echo $website[0];
私は間違いなくこれに関する助けに感謝します!