php運(yùn)行出現(xiàn)Call to undefined function curl_init()
2016-07-01 07:04:41
12563
curl_init -- 初始化一個(gè)CURL會(huì)話,如果提示Call to undefined function curl_init那么需要如下操作即可。
在網(wǎng)上下載了一個(gè)模擬登陸discuz論壇的php程序范例,試運(yùn)行時(shí)出現(xiàn)“Call to undefined function curl_init”這個(gè)錯(cuò)誤提示,沒有定義的函數(shù),也就是php還沒打開對(duì)curl_init函數(shù)的支持。Google了一番終于解決了,方法如下:
系統(tǒng)環(huán)境,WIN2003 IIS6,PHP版本5.2.12
在裝好PHP后,執(zhí)?類似$ch = curl_init();這樣的語句,出現(xiàn)Call to undefined function curl_init()的錯(cuò)誤提示。
解決方法如下:
1、在php.ini中找到extension=php_curl.dll,去掉前面的,php.ini一般在c:windows下面。
2、在php.ini中找到extension_dir = "ext",去掉前面的;,改為extension_dir = "C:php5ext"?
"C:php5ext"只是示例,即擴(kuò)展指向的路徑要對(duì)
3、php_curl.dll、libeay32.dll、ssleay32.dll、php5ts.dll都拷到system32下面去。
4、然后重啟電腦,故障解決。
注意:在PHP的5.2.8版本中不知道什么原因,用這方法無法解決,換成了5.2.12才解決掉。
以windows下的php+apache為例。
首先,打開php.ini,找到“extension=php_curl.dll”,然后去掉前面的“;”注釋,重啟apache即可。
如果還出現(xiàn)此類問題,先檢查php.ini的extension_dir值是哪個(gè)目錄,在那個(gè)目錄下檢查有無php_curl.dll,沒有的話請(qǐng)下載php_curl.dll,再把php目錄中的libeay32.dll和ssleay32.dll拷到c:windowssystem32里面,重啟apache,OK!
在Ubuntu 下?行php,總是提示Call to undefined function curl_init(),原因沒有安轉(zhuǎn):php5-curl
與curl相關(guān)的內(nèi)容見:http://www.tjdsmy.cn/zh-cn/intrepid/php5-curl
CURL is a library for getting files from FTP, GOPHER, HTTP server.
PHP5 is an HTML-embedded scripting language. Much of its syntax is borrowed from C, Java and Perl with a couple of unique PHP-specific features thrown in. The goal of the language is to allow web developers to write dinamically generated pages quickly. This version of PHP5 was built with the Suhosin patch.
H1>
(PHP 4 >= 4.0.2)
curl_init -- 初始化一個(gè)CURL會(huì)話
描述
int curl_init ([string url])
curl_init()函數(shù)將初始化一個(gè)新的會(huì)話,返回一個(gè)CURL句柄供curl_setopt(), curl_exec(),和 curl_close() 函數(shù)使用。如果可選參數(shù)被提供,那么CURLOPT_URL選項(xiàng)將被設(shè)置成這個(gè)參數(shù)的值。你可以使用curl_setopt()函數(shù)人工設(shè)置。
例 1. 初始化一個(gè)新的CURL會(huì)話,且取回一個(gè)網(wǎng)頁(yè)
<?php
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, "http://www.tjdsmy.cn/");
curl_setopt ($ch, CURLOPT_HEADER, 0);
curl_exec ($ch);
curl_close ($ch);
?>
參見:curl_close(), curl_setopt()