I used cURL to get data from another site. Sometimes it shows data, and sometimes an empty result
Here is my code
function 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);
return $ data;
}
$ returned_content = get_data ('www.example.com');
echo $ returned_content;
source share