Home php Php curl + https

Php curl + https

Author

Date

Category

Good day. It is necessary to parse several pages from https://www.sravni.ru/ , some time ago the script stopped working ( it used to be http : //www.sravni.ru/) but whatever I do I can not get the page. Tried and prohibited the verification of certificates and substituted the certificate – the result in any case is “Unknown SSL protocol error in connection to www.sravni.ru:443”
One of the options below:

function get_web_page ($ url)
{
    $ ch = curl_init ($ url);
    curl_setopt ($ ch, CURLOPT_AUTOREFERER, true);
    curl_setopt ($ ch, CURLOPT_COOKIESESSION, true);
    curl_setopt ($ ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt ($ ch, CURLOPT_FORBID_REUSE, false);
    curl_setopt ($ ch, CURLOPT_FRESH_CONNECT, false);
    curl_setopt ($ ch, CURLOPT_HEADER, false);
    curl_setopt ($ ch, CURLOPT_VERBOSE, true);
    curl_setopt ($ ch, CURLOPT_CONNECTTIMEOUT, 5);
    curl_setopt ($ ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
    curl_setopt ($ ch, CURLOPT_MAXREDIRS, 10);
    curl_setopt ($ ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
    curl_setopt ($ ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
    curl_setopt ($ ch, CURLOPT_TIMEOUT, 5);
 curl_setopt ($ ch, CURLOPT_USERAGENT, "Mozilla / 5.0 (Windows NT 5.1; rv: 31.0) Gecko / 20100101 Firefox / 31.0");
    $ 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;
}

tried this:

curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, false);

… and this:

curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt ($ ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt ($ ch, CURLOPT_CAINFO, getcwd (). "/www.sravni.ru.crt");

Which way to dig?

PS: php 5.4, ssl is included.
In some version I got it once – Protocol “https” not supported or disabled in libcurl


Answer 1, authority 100%

Now spars without any problems:

$ url = 'https://www.sravni.ru/';
if ($ curl = curl_init ()) {
  curl_setopt ($ curl, CURLOPT_URL, $ url);
  curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, true);
  curl_setopt ($ curl, CURLOPT_FOLLOWLOCATION, true);
   curl_setopt ($ curl, CURLOPT_CONNECTTIMEOUT, 30);
  curl_setopt ($ curl, CURLOPT_USERAGENT, 'Bot 1.0');
  $ html = curl_exec ($ curl);
  curl_close ($ curl);
}
echo $ html;

PHP Version 5.6.27
curl 7.51.0

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions