問題描述
curl 在我的共享主機上無法正常工作 (curl not working in the right way on my shared hosting)
我的問題是 curl
在我的主機上不能以正確的方式工作,但在我的本地主機上卻能正常工作。
這是我用來測試的代碼:
$url = 'https://www.instagram.com/nasa/?__a=1';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("User‑Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en‑US; rv:1.8.1.15) Gecko/20080623 Firefox/2.0.0.15") );
curl_setopt($ch, CURLOPT_NOBODY, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result= curl_exec ($ch);
curl_close ($ch);
echo style_print_r( $result );
在我的託管中,它似乎試圖加載整個頁面:(
如何解決這個問題?
參考解法
方法 1:
Please check the Curl in your shared hosting
If you want to check whether the hosting service you are using has activated CURL or not, please create a php file with the following contents:
<?php
// Script to test if the CURL extension is installed on this server
// Define function to test
function _is_curl_installed() {
   if (in_array ('curl', get_loaded_extensions())) {
       return true;
   }
   else {
       return false;
   }
}
// Ouput text to user based on test
if (_is_curl_installed()) {
 echo "cURL is <span style=\"color:blue\">installed</span> on this server";
} else {
 echo "cURL is NOT <span style=\"color:red\">installed</span> on this server";
}
?>
You can save the file with any file name, for example curl.php, after you save it, please access it via your web browser, for example at the address www.yourdomain.com/curl.php to find out the results.
(by John、Farhan Yudhi Fatah)