Scenario:
file_ get_ The contents () function is used to read the contents of a file into a string. It is one of the commonly used functions to read the contents of a file.
But sometimes file is used on the server_ get_ When the contents() function requests the URL file of HTTPS protocol, an error will be reported, and the file content cannot be read correctly,
reason:
The server is not properly configured with HTTPS certificate
Solution: (three solutions)
Method 1:
Download HTTPS certificate to server
The server downloads this certificate, http://curl.haxx.se/ca/cacert.pem
Php.ini configuration
openssl.cafile = “/ etc/SSL/certs/cacert. PEM”// the path where you actually download the certificate
Restart PHP
Method 2:
Use the curl function to process HTTPS parameters and obtain the file content
<?php
function getSSLPage($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSLVERSION,3);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
var_dump(getSSLPage("https://xxx.xxx.xxx"));
?>
Method 3:
Make file_ get_ The contents() function skips HTTPS authentication
$stream_opts = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false,
]
];
$response = file_get_contents("https://xxx.xxx.xxx",false,stream_context_create($stream_opts));
It is recommended to use curl function instead of file in development_ get_ Contents() function.
Read More:
- cURL error 35:error:140770FC:SSL routines:SSL_23_GET_SERVER_HELLO:unknown protocol
- wget OpenSSL: error:1407742E:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version
- An error is reported when you open HTTPS with the following error code: SSL_ error_ ssl_ Disabled) (solved)
- The file server reports an error of 413, and the file uploaded by nginx reports an error of 413 request entity too large
- Python uses requests to request and reports SSL: CERTIFICATE_VERIFY_FAILED error
- Reverse function: reverses container contents
- PHP artisan cache: clear command reports an error
- When we crawl to the HTTPS website, the SSL certificate error is solved
- FreeRDP installation configuration (error message: SSL_read: Failure in SSL library (protocol error?))
- Error an unexpected error occurred:“ https://registry.npm.taobao.orgnpm/element-ui : get
- Failed to load resource: net::ERR_SSL_PROTOCOL_ERROR
- The C language qsort() function reports an error for overflow of – 2147483648 and 2147483648
- Idea svn connection https error report: E230001: Server SSL certificate verification failed: certificate issued
- Vue install reports an error operation not allowed
- fatal: protocol ‘https‘ is not supported
- Record the pits you stepped on – NSS error – 5938 (PR_ END_ OF_ FILE_ ERROR), curl: (35) Encountered end of file
- GeTx reports an error in the get request using getconnect
- After upgrading windows 11, Wireshark can’t get list of interfaces: packetgetadapternames reports an error
- PHP in Windows combined with bat batch processing to achieve multi process verification proxy server function
- An idea to solve Warning move_uploaded_file, failed to open stream in the process of php uploading files