Php curl在我的共享主机上没有以正确的方式工作
我的问题是,Php curl在我的共享主机上没有以正确的方式工作,php,curl,https,file-get-contents,shared-hosting,Php,Curl,Https,File Get Contents,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
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 );
在my localhost中,代码的结果如下:
但在我的主持下,结果是:
在我的主机中,它似乎试图加载整个页面:(
如何解决这个问题
编辑:这是在我的主机中打印的源代码:
请检查共享主机中的卷曲 如果要检查正在使用的托管服务是否已激活CURL,请创建包含以下内容的php文件:
<?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";
}
?>
您可以使用任何文件名保存该文件,例如curl.php,保存后,请通过web浏览器访问它,例如在地址处查找结果。Run
phpinfo()
在共享主机上查看与本地环境的差异。即使用phpinfo()制作脚本或在现有脚本中插入一行
。可能还值得检查错误-当你说在本地主机和你的主机上使用不同的工作方式时,你的意思是你在每个主机上运行完全相同的Php代码吗?@Progrock是的,完全相同,但在我的本地主机上,它是wokring,但在我的主机上,它加载整个页面,如instagram徽标、元、脚本和样式s、 尝试获取你的卷发的详细信息,请参见: