curl_init() function not working

2019-01-02 15:49发布

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);

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 lampp
15条回答
若你有天会懂
2楼-- · 2019-01-02 16:11

function curl_int(); cause server error,install sudo apt-get install php5-curl restart apache2 server .. it will work like charm

查看更多
残风、尘缘若梦
3楼-- · 2019-01-02 16:14

Just install the last version of wamp server.

查看更多
忆尘夕之涩
4楼-- · 2019-01-02 16:18

Just adding my answer for the case where there are multiple versions of PHP installed in your system, and you are sure that you have already installed the php-curl package, and yet Apache is still giving you the same error.

curl_init() undefined even if php-curl is enabled in Php 7.

查看更多
长期被迫恋爱
5楼-- · 2019-01-02 16:19

For Windows, if anybody is interested, uncomment the following line (by removing the ;) from php.ini

;extension=php_curl.dll

Restart apache server.

查看更多
牵手、夕阳
6楼-- · 2019-01-02 16:20

(Trying to get Curl working via PHP and Apache on Windows...)

I kept getting an error saying: Call to undefined function 'curl_init()'

I made sure I had enabled curl with this line in my php.ini file: extension=php_curl.dll

I made sure the extension_dir variable was being set properly, like this: extension_dir = "ext"

I was doing everything everyone else said on the forums and curl was not showing up in my call to phpinfo(), and I kept getting that same error from above.

Finally I found out that Apache by default looks for php.ini in the C:\Windows folder. I had been changing php.ini in my PHP installation folder. Once I copied my php.ini into C:\Windows, everything worked.

Took me forever to figure that out, so thought I'd post in case it helps someone else.

查看更多
何处买醉
7楼-- · 2019-01-02 16:25

RusAlex answer is right in that for Apache you have to install and enable curl and restart your apache service:

sudo apt-get install php5-curl
sudo service apache2 restart

On my Ubuntu Server with nginx and php5-fpm I however ran into the following problem. I had to restart nginx and php5-fpm like so:

sudo service nginx restart
sudo service php5-fpm restart

But I had non-working php5-fpm processes hanging around, which apparently is a bug in ubuntu https://bugs.launchpad.net/ubuntu/+source/php5/+bug/1242376 So I had to kill all idle php5-fpm processes to able to restart php5-fpm so that the curl module is actually loaded

sudo kill <Process Id of php5-fpm Process)
查看更多
登录 后发表回答