我正在尝试获取页面的内容以在我的网站上使用它。
我需要this链接中的内容。
然后我想从该 json 页面获取“figureString”, 所以我可以把它放在this链接中。
我尝试使用curl,但它说他们因为ddos尝试而阻止了我。 我无法使用 file_get_contents,它显示 无法打开流:HTTP 请求失败! get_remote_data 也不起作用。
<?php
echo "WELCOME ".$r->habboname;
$curl_handle=curl_init();
curl_setopt($curl_handle, CURLOPT_URL, 'https://www.habbo.nl/api/public/users?name='.$r->habboname);
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_USERAGENT, 'myproject');
$query = curl_exec($curl_handle);
curl_close($curl_handle);
echo 'Query: '.$query;
$json = json_decode($query, true);
echo '<pre>' . print_r($json, true) . '</pre>';
echo get_remote_data('https://www.habbo.nl/api/public/users?name='.$r->habboname, true );
file_get_contents(filename)
?>
我得到了答案:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://www.habbo.nl/api/public/users?name='.$r->habboname);
curl_setopt($ch, CURLOPT_USERAGENT, 'github.com/gerbenjacobs/habbo-api v2.2.0');
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
// urls at /extradata/ require javascript/cookie validation, trick them.
$data = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
$json=json_decode($data, true);
echo $json['figureString'];