Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fatal error: Call to undefined function http_get()

I tried to make cross domain request in php coding using http_get. In my server, there is no required modules installed. I dont know what to install to make posible of doing http_get.

The error which i got was

Fatal error: Call to undefined function http_get() in C:\xampp\htdocs\article\index.php on line 2

I tried to do so (PECL pecl_http >= 0.1.0) http_get — Perform GET request

but, i did not find out solution.

So, please help me to run http_get coding. Thanks in advance.

like image 892
Venkatesh S Avatar asked Jan 02 '15 12:01

Venkatesh S


2 Answers

I think that you have to enable extension=php_http.dll in your php.ini file and after that restart your Apache Server.
I advise you to use cURL instead of http_get() (same manipulation, you have to enable extension=php_curl.dll and restart apache)

Hope that Helps :)

like image 70
Halayem Anis Avatar answered Nov 10 '22 07:11

Halayem Anis


To directly answer the question, you've to enable extension=php_http.dll in php.ini and restart apache, but there's absolutely no need to use http_get() in our days.

Here's 3 good alternatives:

  1. The php curl library
  2. file_get_contents()
  3. copy()

Curl usage:

// Get cURL resource
$curl = curl_init();
// Set some options - we are passing in a useragent too here
curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_URL => 'http://testcURL.com/?item1=value&item2=value2',
    CURLOPT_USERAGENT => 'User Agent X'
));
// Send the request & save response to $resp
$resp = curl_exec($curl);
// Close request to clear up some resources
curl_close($curl);

file_get_content() usage:

$my_var = file_get_contents("https://site/");

copy() usage:

copy("https://site/image.png", "/local/image.png");
like image 38
Pedro Lobito Avatar answered Nov 10 '22 06:11

Pedro Lobito