I am at wit's end here. I have set up a LAMP server for a project I've been working on recently (it's for school). I am trying to obtain the public IP address from my server with PHP using curl. I used following code to obtain it:
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "http://ipecho.net/plain");
$host = curl_exec($ch);
curl_close($ch);
It works great on localhost on my home PC. Sadly, the Ubuntu server doesn't comply. When I echo the result, I get a formatted message saying:
NOT FOUND: The request URL "/plain/" was not found on this server.
I don't really know what to do here. cURL should work too, I have installed the right package.
SIDENOTE:
I have also tried via file_get_contents()
(Which also worked on my home PC) but on the server, it just returned following message:
Warning: file-get-contents("http://ipecho.net/plain") failed to open stream: HTTP request failed! HTTP/1.1 202
Could these two things be related to the same problem?