我使用 cURL 从另一个网站获取数据。有时显示数据,有时显示空结果
这是我的代码
函数 get_data($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
$agent=$_SERVER["HTTP_USER_AGENT"];
curl_setopt($ch,CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
$data = curl_exec($ch);
curl_close($ch);
返回$数据;
}
$returned_content = get_data('www.example.com');
回声 $returned_content;