简体   繁体   中英

Error in php using curl_init()

I'm completely newbie in 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?

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 ; to uncomment it. Restart xampp.

What is your Xampp version?

If your version is >= 1.7.1 then follow the following instruction:-

  1. Open ..\\xampp\\php\\php.ini
  2. Uncomment the following line on your php.ini file by removing the semicolon.

;extension=php_curl.dll

  1. Restart your apache server

Otherwise, follow following instruction:-

  1. Open the following files-

..\\xampp\\apache\\bin\\php.ini

..\\xampp\\php\\php.ini

..\\xampp\\php\\php4\\php.ini

2) Uncomment the following line on your php.ini file by removing the semicolon.

;extension=php_curl.dll

3) Restart your apache server.

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. Please read: 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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