J'ai trouvé cette fonction qui fait un excellent travail (IMHO): http://nadeausoftware.com/articles/2007/06/php_tip_how_get_web_page_using_curlPHP CURL et HTTPS
/**
* 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;
}
Le seul problème que j'ai est que cela ne fonctionne pas pour https: //. Anny idées ce que je dois faire pour que cela fonctionne pour https? Merci!
définir "ne fonctionne pas" s'il vous plaît. –
curl par défaut vérifiez si le certificat SSL est valide ... vous pouvez désactiver ce comportement si vous vous êtes auto-signé le certificat en question – RageZ
@RegeZ - comment faire votre suggestion? – StackOverflowNewbie