on the problem of CURL remotely fetching web page data in PHP.
needs to grab the contents of the dictionary, and the local test can return FALSE when placed on the server.
I saw that some related questions were raised before https://codeshelper.com/q/10.
, but with the addition of CURLOPT_USERAGENT, it is still ineffective. Please take a look at it
<?php
function curl_get_contents($url, $timeout = 15) {
// dump($url);
$curlHandle = curl_init();
curl_setopt( $curlHandle , CURLOPT_URL, $url );
curl_setopt( $curlHandle , CURLOPT_RETURNTRANSFER, 1 );
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYPEER, FALSE); // https hosts
curl_setopt($curlHandle, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curlHandle,CURLOPT_USERAGENT,"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
curl_setopt( $curlHandle , CURLOPT_TIMEOUT, $timeout );
// dump(curl_error($curlHandle));
// dump($curlHandle);
$result = curl_exec( $curlHandle );
curl_close( $curlHandle );
return $result;
}
$url = "https://www.ldoceonline.com/dictionary/january";
$html = curl_get_contents($url, 60);
var_dump($html);
?>