简体   繁体   English

使用curl_init()的PHP错误

[英]Error in php using curl_init()

I'm completely newbie in PHP. 我是PHP的新手。

I have tried example code from this site . 我已经尝试过该站点的示例代码。 but it gives following error: 但它给出以下错误:

Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\g\test1.php on line 3

Am I missing something? 我想念什么吗? It says undefined function curl_init() so where should I define it? 它说了未定义的函数curl_init(),那么我应该在哪里定义它呢?

Code:- 码:-

<?php
// create a new cURL resource
$ch = curl_init();

// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, "http://www.example.com/");
curl_setopt($ch, CURLOPT_HEADER, 0);

// grab URL and pass it to the browser
curl_exec($ch);

// close cURL resource, and free up system resources
curl_close($ch);
?>

I assume you're using xampp as for your error shows it, locate php.ini in xampp directory probably located in C:\\Program Files\\xampp\\php\\php.ini and search for ;extension=php_curl.dll remove the ; 我假设您正在使用xampp,因为您的错误表明了这一点,请在可能位于C:\\Program Files\\xampp\\php\\php.ini xampp目录中找到php.ini ,然后搜索;extension=php_curl.dll删除; to uncomment it. 取消注释。 Restart xampp. 重新启动xampp。

What is your Xampp version? 您的Xampp版本是什么?

If your version is >= 1.7.1 then follow the following instruction:- 如果您的版本> = 1.7.1,请遵循以下说明:-

  1. Open ..\\xampp\\php\\php.ini 打开.. \\ xampp \\ php \\ php.ini
  2. Uncomment the following line on your php.ini file by removing the semicolon. 通过删除分号,取消对php.ini文件中以下行的注释。

;extension=php_curl.dll ;延长= php_curl.dll

  1. Restart your apache server 重新启动Apache服务器

Otherwise, follow following instruction:- 否则,请遵循以下说明:

  1. Open the following files- 打开以下文件-

..\\xampp\\apache\\bin\\php.ini .. \\ XAMPP的\\ apache的\\斌\\ php.ini中

..\\xampp\\php\\php.ini .. \\ XAMPP \\ PHP \\ php.ini中

..\\xampp\\php\\php4\\php.ini .. \\ XAMPP \\ PHP \\ PHP4 \\ php.ini中

2) Uncomment the following line on your php.ini file by removing the semicolon. 2)通过删除分号取消注释php.ini文件中的以下行。

;extension=php_curl.dll ;延长= php_curl.dll

3) Restart your apache server. 3)重新启动apache服务器。

check if curl is enable or not 检查是否启用卷曲

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, 0);
$data = curl_exec($ch);
curl_close($ch);

Looks like you're on Windows and don't have the curl extension enabled. 看起来您在Windows上,并且未启用curl扩展。 Please read: http://php.net/manual/en/install.windows.extensions.php . 请阅读: http : //php.net/manual/en/install.windows.extensions.php You need to find php_curl.dll , put it in your extension directory and load it from your php.ini 您需要找到php_curl.dll ,将其放在扩展目录中并从php.ini加载它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM