我要利用curl函數進行數據采集時發現提示Call to undefined function curl_init錯誤了,后來從官網了解到因為curl默認不是php開啟的函數,我們需要手工打開哦,下面我來給大家介紹開啟curl函數,例:
- $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;//顯示返回信息
結果出現:Call to undefined function curl_init
解決方法如下:
1.打開php.ini,開啟extension=php_curl.dll
2.檢查php.ini的extension_dir值是哪個目錄,檢查有無php_curl.dll,沒有的請下載php_curl.dll,再把php目錄中的libeay32.dll,ssleay32.dll拷到c:windowssystem32里面
如果修改之后還有問題,在httpd.conf文件中加上,LoadFile 動態鏈接庫的完整路徑,比如,此處php需要擴展curl,因此解決方法就是在httpd.conf文件中加上:
- LoadFile d:/php/libeay32.dll
- LoadFile d:/php/ssleay32.dll
新聞熱點
疑難解答