When I wanted to use the curl function for data collection, I found an error message called Call to undefined function curl_init. 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. Let me introduce to you how to enable curl. function.
Example
The code is as follows
代码如下 |
复制代码 |
$ch = curl_init(); //初始化curl
curl_setopt($ch, CURLOPT_URL, $url);//设置链接
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//设置是否返回信息
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//设置HTTP头
curl_setopt($ch, CURLOPT_POST, 1);//设置为POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);//POST数据
$response = curl_exec($ch);//接收返回信息
if(curl_errno($ch)){//出错则显示错误信息
print curl_error($ch);
}
curl_close($ch); //关闭curl链接
echo $response;//显示返回信息
|
|
Copy code
|
$ch = curl_init(); //Initialize curl
curl_setopt($ch, CURLOPT_URL, $url);//Set link
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//Set whether to return information
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//Set HTTP header
curl_setopt($ch, CURLOPT_POST, 1);//Set to POST mode
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_data);//POST data
$response = curl_exec($ch);//Receive return information
if(curl_errno($ch)){//If an error occurs, the error message will be displayed
print curl_error($ch);
}
curl_close($ch); //Close curl link
echo $response;//Display return information
The result appears
Call to undefined function curl_init
The solution is as follows:
1. Open php.ini and enable extension=php_curl.dll |
2. Check which directory the extension_dir value of php.ini is, and check whether there is php_curl.dll. If not, please download php_curl.dll, and then copy libeay32.dll and ssleay32.dll in the php directory to c:windowssystem32
There are still problems after the modification
Add in the httpd.conf file:
Full path of LoadFile dynamic link library
For example, php needs to extend curl here, so the solution is to add: to the httpd.conf file
LoadFile d:/php/libeay32.dll
LoadFile d:/php/ssleay32.dll
This solves the problem
http://www.bkjia.com/PHPjc/632116.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/632116.htmlTechArticleWhen I wanted to use the curl function for data collection, I found an error saying Call to undefined function curl_init. I later learned from the official website Because curl is not a function enabled by PHP by default, we need to do it manually...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn