tags:

views:

385

answers:

3

I am using fopen to retreive the contents of a URL. It works on http URLs but not https URLs

Can anyone see why??

<?php

//this works fine
echo ("<br><br>url 1 is ".OutputURL("http://nuenergy.acornsoftware.com.au/staff/interface/index.php"));

//returns nothing
echo ("<br><br>url 2 is ".OutputURL("https://nuenergy.acornsoftware.com.au/staff/interface/index.php"));

function OutputURL($url)
{
  $handle = fopen($url, "r");
  $contents = stream_get_contents($handle);
  fclose($handle);
  return $contents;
}
//
?>
+2  A: 

The problem isn't with PHP not returning anything for HTTPS, it's your file not outputting anything for the HTTPS version of the file. When I view the HTTP version, it outputs a small XML diagram representing some sort of 'File Not Found' error. When I view the HTTPS form of the file, it returns a blank page, absolutely no content in the source code. You need to look at your Apache configurations and make sure it's pointing to all the files properly.

animuson
A: 

It'll either be that your apache/php setup does not support https via fopen or your server's firewall has blocked this type of connection.

Ben Rowe
+2  A: 

You need to have OpenSSL installed and configured with PHP, I recommend you ask this on ServerFault.

Also, you can just use file_get_contents() instead of OutputURL().

Alix Axel