Php prompts Call to undefined function curl_init () when using the curl function ()

Source: Internet
Author: User

Yesterday when I used curl to write an api interface, I found that the Call to undefined function curl_init () error was prompted when running the curl function. From the error, the curl_init () function is not defined, later I learned that this function must open a file in php. The specific method is as follows.

I wrote the program code like this.

The Code is as follows: Copy code

?? Php
// Initialize a cURL object
$ Curl = curl_init ();

// Set the URL you want to capture
Curl_setopt ($ curl, CURLOPT_URL, 'HTTP: // www. bKjia. c0m ');

// Set the header
Curl_setopt ($ curl, CURLOPT_HEADER, 1 );

// Set the cURL parameter to save the result to the string or output to the screen.
Curl_setopt ($ curl, CURLOPT_RETURNTRANSFER, 1 );

// Run cURL to request the webpage
$ Data = curl_exec ($ curl );

// Close the URL request
Curl_close ($ curl );

// Display the obtained data
Var_dump ($ data );

The result shows: Call to undefined function curl_init (). Later, Baidu provided some solutions for your reference.


Modify the configuration under windows + apache:

1. Modify php. ini and remove the semicolon before extension = php_curl.dll.
2. Copy the libeay32.dll and ssleay32.dll (C: AppServphp5) files to the system32 directory.
3. Restart Apache (services. msc ).


Linux + apache solution:

Install the curl package. If you use ubuntu, open the new software package manager to search for curl and install curl.

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.