I
I
Ilya Beloborodov2016-07-26 18:48:38
PHP
Ilya Beloborodov, 2016-07-26 18:48:38

Why does php require an ssl certificate?

The server is on the computer.
With such a schedule

<?php
file_get_contents('https://vk.com');
?>

here is the error
Warning : file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed in /Applications/AMPPS/www/pf.loc/test.php on line 2
Warning : file_get_contents(): Failed to enable crypto in /Applications/AMPPS/www/pf.loc/test.php on line 2
Warning : file_get_contents( https://vk.com): failed to open stream: operation failed in / Applications/AMPPS/www/pf.loc/test.php on line 2
I know this shouldn't happen because everything worked on the other server.
php.ini has extension=openssl.so

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexyz Canson, 2018-12-13
@kowap

$arrContextOptions=array(
    "ssl"=>array(
        "verify_peer"=>false,
        "verify_peer_name"=>false,
    ),
);  
$sw=file_get_contents(ЛИНК, false, stream_context_create($arrContextOptions));

S
seopublic, 2019-07-10
@seopublic

function file_get_contents_curl( $url ) {

  $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 );

  $data = curl_exec( $ch );
  curl_close( $ch );

  return $data;

}

Затем просто используйте file_get_contents_curl вместо file_get_contents всякий раз, когда вы вызываете URL-адрес, начинающийся с https.

O
OnYourLips, 2016-07-26
@OnYourLips

https://github.com/composer/composer/issues/3346

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question