The solution to the error of the file_get_contents function grabbing the https address in PHP (two methods)

method one:

In php, grab the https website, prompt the following error content:

Warning: file_get_contents() [function.file-get-contents]: failed to open stream: Invalid argument in I:Webmyphpa.php on line 16

Open the php.ini file and find; extension=php_openssl.dll, remove the double quotes ";" and restart the web server.

For apache server, you can enable mod_ssl module testing at the same time.

If it is not convenient to modify the server configuration, you can refer to the following function to solve it:

Code example:

 

<?php
//file_get_contents抓取https地址内容
function getCurl($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
$result = curl_exec($ch);
curl_close ($ch);
return $result;
}

 

Method Two:

In php, when using the file_get_contents function to fetch the content of a website whose url starts with https, an error warning similar to the following will appear:

Warning: file_get_contents(https://127.0.0.1/index.php) [function.file-get-contents]: failed to open stream: Invalid argument in E:\website\blog\test.php on line 25

Open php.ini and find; extension=php_openssl.dll, remove the double quotes ";" and restart the web server.

Apache can simultaneously enable mod_ssl module testing

The above content has shared with you two methods to solve the problem of the file_get_contents function in PHP grabbing the https address. I hope it will help you.

Guess you like

Origin blog.csdn.net/sun124608666/article/details/105856027