BenM
BenM

Reputation: 53208

file_get_contents() returns nothing

I am trying to retrieve data from the US National Archives' website using PHP's file_get_contents() function as I have in the past for making similar scripts. For some reason though, in this instance the function does not retrieve any of the file's content.

I must confess that I haven't much experience with this kind of work. Could someone indicate why the file might not be correctly returned, even though the file displays fine when I manually type the URL into the address bar. Here's the source code (or a minimal version which doesn't output anything):

   $asn = $_REQUEST['asn'];
$format = $_REQUEST['output'];
  $data = array();

if(!empty($asn))
{
    $url_to_get = 'http://aad.archives.gov/aad/print-record-detail.jsp?dt=893&mtch=1&tf=F&q=31371273&bc=sl,fd&rpp=10&pg=1&rid=2546302';
    $content = file_get_contents($url_to_get);
    echo $content;
}

And the URL we're trying to access is > http://aad.archives.gov/aad/print-record-detail.jsp?dt=893&mtch=1&tf=F&q=31371273&bc=sl,fd&rpp=10&pg=1&rid=2546302

Is it possible that running the script on localhost might be causing an issue here?

Upvotes: 1

Views: 3601

Answers (1)

Jon
Jon

Reputation: 437444

There will definitely be a warning in case of failure. That particular URL wants PHP to be configured with SSL support, because running on stock it gives me:

failed to open stream: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?

This tells me that I have to enable the openssl extension for PHP.

Upvotes: 8

Related Questions