curl_init()函数不起作用 [英] curl_init() function not working

查看:227
本文介绍了curl_init()函数不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试了在POST请求中进行PHP Post请求的思考这可能对我有用,我的代码在下面给出

Hi I tries PHP Post Request inside a POST Request thinking it might be useful to me and my code is given below

$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文件中出现以下错误

form the index.php file and index2.php is another file in the same directory and when i open the page i get the following error in my error.log file

[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

我想做的是,我有一个预订表格,可以发送邮寄请求,然后我要处理邮寄值,然后再次将邮寄请求发送给贝宝

What i want to do is I have a reservation form that send post request and then i want to process post values and send again post request to paypal

推荐答案

您需要为PHP安装CURL支持.

You need to install CURL support for php.

在Ubuntu中,您可以通过安装它

In Ubuntu you can install it via

sudo apt-get install php5-curl

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

If you're using apt-get then you won't need to edit any PHP configuration, but you will need to restart your Apache.

sudo /etc/init.d/apache2 restart

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

If you're still getting issues, then try and use phpinfo() to make sure that CURL is listed as installed. (If it isn't, then you may need to open another question, asking why your packages aren't installing.)

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

这篇关于curl_init()函数不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆