Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Localhost URL works in browser but returns bool(false) for PHP curl_exec

Tags:

php

curl

I have the following PHP code:

$curl = curl_init();
curl_setopt ($curl, CURLOPT_URL, $URL);
curl_setopt ($curl, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec ($curl);

echo $html;

whith following result:

  • OK for a $URL like "http://www.google.com"

  • KO for a $URL like "http://localhost/index.html", and returning bool(false) when I do a var_dump

and this even though the browser can display http://localhost/index.html with no problem. I am running a xampp apache server on the localhost.

I cannot figure out what the problem is. Any help would be much appreciated.

like image 972
Timothée HENRY Avatar asked Jan 05 '11 13:01

Timothée HENRY


1 Answers

You should make sure that your Apache listens on the correct interfaces. I had this problem once on a Vist machine: Apache (XAMP) was listening only on IPv4, but on Vista "localhost" resolves to an IPv6 address by default.

To disable the IPv6 address, edit you %system32%\drivers\etc\hosts file and remove the ::1 line.

like image 123
xrstf Avatar answered Nov 19 '22 02:11

xrstf