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:02

You need to install CURL support for php.

In Ubuntu you can install it via

sudo apt-get install php5-curl

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

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

There is an installation manual in the PHP CURL documentation.

查看更多
人间绝色
3楼-- · 2019-01-02 16:02

Step 1 :

C:/(path to php folder)/php.ini
enable extension=php_curl.dll

(remove the ; at the end of the line)

Step 2 :

Add this to Apache/conf/httpd.conf (libeay32.dll, ssleay32.dll, libssh2.dll find directly in php7 folder)

# load curl and open ssl libraries
 LoadFile "C:/(path to php folder)/libeay32.dll"
 LoadFile "C:/(path to php folder)/ssleay32.dll"
 LoadFile "C:/(path to php folder)/libssh2.dll"
查看更多
萌妹纸的霸气范
4楼-- · 2019-01-02 16:02

I got this error using PHP7 / Apache 2.4 on a windows platform. curl_init worked from CLI but not with Apache 2.4. I resolved it by adding LoadFile directives for libeay32.dll and ssleay32.dll:

LoadFile "C:/path/to/Php7/libeay32.dll"
LoadFile "C:/path/to/Php7/ssleay32.dll"
LoadFile "C:/path/to/Php7/php7ts.dll"
LoadModule php7_module "C:/path/to/Php7/php7apache2_4.dll"
查看更多
后来的你喜欢了谁
5楼-- · 2019-01-02 16:06

For Ubuntu: add extension=php_curl.so to php.ini to enable, if necessary. Then sudo service apache2 restart

this is generally taken care of automatically, but there are situations - eg, in shared development environments - where it can become necessary to re-enable manually.

The thumbprint will match all three of these conditions:

  1. Fatal Error on curl_init() call
  2. in php_info, you will see the curl module author (indicating curl is installed and available)
  3. also in php_info, you will see no curl config block (indicating curl wasn't loaded)
查看更多
春风洒进眼中
6楼-- · 2019-01-02 16:10

In my case, in Xubuntu, I had to install libcurl3 libcurl3-dev libraries. With this command everything worked:

sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
查看更多
不再属于我。
7楼-- · 2019-01-02 16:11

I got it working in ubuntu 16.04 by following steps.My php version was 7.0

sudo apt-get install php7.0-curl

sudo service apache2 restart

i got it from this link check here for more details

查看更多
登录 后发表回答