小编典典

curl_init()函数不起作用

php

嗨,我尝试在POST请求中尝试PHPPost请求,认为这可能对我有用,下面给出了我的代码

$sub_req_url = "http://localhost/index1.php";

$ch = curl_init($sub_req_url);
$encoded = '';

// include GET as well as POST variables; your needs may vary.
foreach($_GET as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

foreach($_POST as $name => $value) {
  $encoded .= urlencode($name).'='.urlencode($value).'&';
}

// chop off last ampersand
$encoded = substr($encoded, 0, strlen($encoded)-1);

curl_setopt($ch, CURLOPT_POSTFIELDS,  $encoded);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_exec($ch);
curl_close($ch);

形成index.php文件,而index2.php是同一目录中的另一个文件,当我打开页面时,我的error.log文件中出现以下错误

[Sat Dec 18 15:24:53 2010] [error] [client ::1] PHP Fatal error:  Call to undefined function curl_init() in /var/www/testing1/index.php on line 5

我想要做的是我有一个发送发帖请求的预订表格,然后我想处理发帖值并再次将发帖请求发送到贝宝


阅读 437

收藏
2020-05-26

共1个答案

小编典典

您需要为php安装CURL支持。

在Ubuntu中,您可以通过安装

sudo apt-get install php5-curl

如果使用apt-get,则无需编辑任何PHP配置,但需要重新启动Apache。

sudo /etc/init.d/apache2 restart

如果仍然遇到问题,请尝试并使用phpinfo()来确保CURL被列为已安装。(如果不是,那么您可能需要打开另一个问题,询问为什么不安装您的软件包。)

PHP CURL文档中有一个安装手册。

2020-05-26