PHP Curl&HTTPS不工作

PHP Curl&HTTPS不工作,php,curl,https,Php,Curl,Https,因此,我使用PHP和Curl尝试从下载https weburl,但它不起作用,以下是我迄今为止的代码一个简单的Curl和另一个更高级的Curl,两者都不起作用sadl.: // connect via SSL, but don't check cert $ch=curl_init('https://www.g2crowd.com'); curl_setopt ($ch, CURLOPT_CAINFO, "cacert.pem"); curl_setopt($ch, CURLOPT_VERBOSE

因此,我使用PHP和Curl尝试从下载https weburl,但它不起作用,以下是我迄今为止的代码一个简单的Curl和另一个更高级的Curl,两者都不起作用sadl.:

// connect via SSL, but don't check cert
$ch=curl_init('https://www.g2crowd.com');
curl_setopt ($ch, CURLOPT_CAINFO, "cacert.pem");
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);  

$content = curl_exec($ch);

echo $content; // show target page
$ckfile = tempnam ("/tmp", 'cookiename');

$url='https://www.g2crowd.com/';
//$url='https://www.google.com';

$ch = curl_init();
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $ckfile );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $ckfile ); 

curl_setopt($ch, CURLOPT_URL,$url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

$headers = [
'Host: www.g2crowd.com',
'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:43.0) Gecko/20100101 Firefox/43.0',
'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language: en-US,en;q=0.5',
'Accept-Encoding: gzip, deflate'    
];
curl_setopt($ch, CURLOPT_CAINFO, 'C:\Users\ivan\Downloads\cacert.pem');

curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_REFERER, "https://www.g2crowd.com/users/c190d528-ab02-4cb5-8467-9362ceaec290");

curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

$server_output = curl_exec ($ch);
if(curl_error($ch))
{
    echo curl_error($ch);
}
else {
    echo 'eureka!';
}

curl_close ($ch);
我试图捕捉旋度误差,所以这里是误差:

1407742E:SSL例程:SSL23\u GET\u SERVER\u HELLO:tlsv1警报协议版本

请帮帮我,我真是束手无策


谢谢

您的openssl程序已过时。我在OSX本机版本上也看到了这一点。如果您在Mac上,则需要下载不同的openssl。或者,使用0打开SSL意味着您没有使用SSL打开。

这应该可以解决您的问题:

$url='https://www.g2crowd.com/';

$ch = curl_init();

curl_setopt( $ch, CURLOPT_AUTOREFERER, TRUE );
curl_setopt( $ch, CURLOPT_HEADER, 0 );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, TRUE );

$server_output = curl_exec( $ch );

curl_close( $ch );
如果不起作用,请尝试:

$url='https://www.g2crowd.com/';
$server_output = file_get_contents( $url );

$i设置在何处和何处?看第18行。嘿,赵,说得好!这是我尝试循环使用各种ssl协议时的调试遗留问题,但即使在设置或删除该参数时,它仍然返回一个错误。福布斯非常感谢您。我正在Windows7机器上的ZendStudio内部使用ZendStudio 13 IDEPHP调试器。那么,这个OpenSSL是我需要在windows上安装的程序还是修改php.ini或其他东西?我还安装了Wamp,我是否应该尝试在Wamp本地php服务器上运行脚本?Thanx寻求帮助Ben!这可能只是我的PHP调试器,但它不工作,我想你尝试过它,它为你工作?请让我知道,如果你测试了它,它工作了。@IvanSimic这个问题几乎可以肯定与你的PHP或至少它的SSL库设置的方式。但这很难远程修复。一般来说,我给的卷发疗法可以治愈很多疾病。试试我提供的第二个选项。解决了,我在Wamp服务器上试过了,这次得到了一个不同的curl错误:检查ssl证书,所以谷歌搜索了解决方案,在Wamp服务器上试过,结果成功了。添加这段代码解决了这个问题:curl_setopt$ch,CURLOPT_CAINFO,'C:\Users\ivan\Downloads\cacert.pem'@伊凡西米奇太棒了!您好,您的curl解决方案结果为空,file\u get\u contents结果出错