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.