PHP的曲线和HTTPS

我发现这个function,做一个了不起的工作(恕我直言): http : //nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curl

/** * Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an * array containing the HTTP server response header fields and content. */ function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "spider", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } 

我唯一的问题是,它不适用于https://。 安妮想法,我需要做什么,使这项工作的HTTPS? 谢谢!

快速修复,请在您的选项中添加:

 curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false) 

或者只是将其添加到您当前的function:

 /** * Get a web file (HTML, XHTML, XML, image, etc.) from a URL. Return an * array containing the HTTP server response header fields and content. */ function get_web_page( $url ) { $options = array( CURLOPT_RETURNTRANSFER => true, // return web page CURLOPT_HEADER => false, // don't return headers CURLOPT_FOLLOWLOCATION => true, // follow redirects CURLOPT_ENCODING => "", // handle all encodings CURLOPT_USERAGENT => "spider", // who am i CURLOPT_AUTOREFERER => true, // set referer on redirect CURLOPT_CONNECTTIMEOUT => 120, // timeout on connect CURLOPT_TIMEOUT => 120, // timeout on response CURLOPT_MAXREDIRS => 10, // stop after 10 redirects CURLOPT_SSL_VERIFYPEER => false // Disabled SSL Cert checks ); $ch = curl_init( $url ); curl_setopt_array( $ch, $options ); $content = curl_exec( $ch ); $err = curl_errno( $ch ); $errmsg = curl_error( $ch ); $header = curl_getinfo( $ch ); curl_close( $ch ); $header['errno'] = $err; $header['errmsg'] = $errmsg; $header['content'] = $content; return $header; } 

我试图用CURL做一些https调用PHP和遇到这个问题。 我注意到在PHP网站上的build议,让我起来和运行: http : //php.net/manual/en/function.curl-setopt.php#110457

请大家停止将CURLOPT_SSL_VERIFYPEER设置为false或0.如果您的PHP安装没有最新的CA根证书包,请将其下载到curl网站并保存到您的服务器上:

http://curl.haxx.se/docs/caextract.html

然后在你的php.ini文件中设置一个path,比如在Windows上:

curl.cainfo = C:\ PHP中\ cacert.pem

closuresCURLOPT_SSL_VERIFYPEER允许中间人(MITM)攻击,这是你不想要的!