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.
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);
If your version is >= 1.7.1 then follow the following instruction:-
;extension=php_curl.dll
Otherwise, follow following instruction:-
..\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.
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