In PHP, The file_get_contents function captures the https address (two methods)

Source: Internet
Author: User
This article uses two methods to solve the problem that the file_get_contents function in PHP fails to capture the https address. For more information, see

This article uses two methods to solve the problem that the file_get_contents function in PHP fails to capture the https address. For more information, see

Method 1:

In php, When you capture an https website, the following error message is displayed:

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 double quotation marks ";". Restart the web server.

If the apache server is used, the mod_ssl module test can be enabled at the same time.

If it is not convenient to modify the server configuration, you can use the following functions to solve the problem:

Sample Code:

<? Php // file_get_contents captures the https address Content 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 2:

In php, when the file_get_contents function is used to capture the website content starting with https, an error warning similar to the following occurs:

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 double quotation marks ";". Restart the web server.

Apache can enable the mod_ssl module for testing at the same time.

The above content is shared with you two ways to solve the problem of the file_get_contents function grabbing https address error in PHP. I hope it will be helpful to you.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.