Php prompt: Call to undefined function curl_init

Source: Internet
Author: User

When I used the curl function for data collection, I found that the Call to undefined function curl_init error was prompted. Later, I learned from the official website that because curl is not a function enabled by php by default, we need to open it manually, next I will introduce how to enable the curl function.

Example

The Code is as follows: Copy code

$ Ch = curl_init (); // initialize curl
Curl_setopt ($ ch, CURLOPT_URL, $ url); // set the link
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1); // sets whether to return information.
Curl_setopt ($ ch, CURLOPT_HTTPHEADER, $ header); // sets the HTTP header
Curl_setopt ($ ch, CURLOPT_POST, 1); // set it to POST
Curl_setopt ($ ch, CURLOPT_POSTFIELDS, $ xml_data); // POST Data
$ Response = curl_exec ($ ch); // receives the returned information
If (curl_errno ($ ch) {// error message displayed
Print curl_error ($ ch );
}
Curl_close ($ ch); // close the curl Link
Echo $ response; // display the returned information

Result

Call to undefined function curl_init

The solution is as follows:

1. Open php. ini and enable extension = php_curl.dll.

2. Check the directory in which the extension_dir value of php. ini is and whether php_curl.dll exists. If not, download php_curl.dll and copy libeay32.dll and ssleay32.dll in the php Directory to c: windowssystem32.

There are still problems after modification

Add the following to the httpd. conf file:

Complete path of LoadFile Dynamic Link Library

For example, php needs to expand curl, so the solution is to add the following in the httpd. conf file:

LoadFile d:/php/libeay32.dll
LoadFile d:/php/ssleay32.dll

This solves the problem.

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.