简体   繁体   中英

php curl fetch content from website is not working

My OS window 7 using Xampp server. In my localhost i got output but using https protocols means i am getting empty response. May I need to update any thing in my below code to get website content.

print_r(curl_version());   

    Array
(
    [version_number] => 470785
    [age] => 3
    [features] => 266141
    [ssl_version_number] => 0
    [version] => 7.47.1
    [host] => i386-pc-win32
    [ssl_version] => OpenSSL/1.0.2d
    [libz_version] => 1.2.7.3
    [protocols] => Array
        (
            [0] => dict
            [1] => file
            [2] => ftp
            [3] => ftps
            [4] => gopher
            [5] => http
            [6] => https
            [7] => imap
            [8] => imaps
            [9] => ldap
            [10] => pop3
            [11] => pop3s
            [12] => rtsp
            [13] => scp
            [14] => sftp
            [15] => smtp
            [16] => smtps
            [17] => telnet
            [18] => tftp
        )

)

My curl program:

// is cURL installed yet?
if (!function_exists('curl_init')){
    die('Sorry cURL is not installed!');
}

// OK cool - then let's create a new cURL resource handle
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://example.com/sites/AAA/default.aspx');
curl_setopt($ch, CURLOPT_REFERER, 'https://example.com/sites/AAA/default.aspx');
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla15-1.0");
//curl_setopt ($ch, CURLOPT_PORT , 8089);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
$output = curl_exec($ch); print_r( $output);
curl_close($ch);

To verify host or peer certificate you need to specify alternate certificates with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option.

When the verify value is 1, curl_easy_setopt will return an error and the option value will not be changed. It was previously (in 7.28.0 and earlier) a debug option of some sorts, but it is no longer supported due to frequently leading to programmer mistakes. Future versions will stop returning an error for 1 and just treat 1 and 2 the same.

When the verify value is 0, the connection succeeds regardless of the names in the certificate. Use that ability with caution!

The default value for this option is 2.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM