tags:

views:

34

answers:

3
+1  Q: 

Read https content

I have a webpage developed in php. I want to read the content of a https://(url) file. how can i read that. I have used file_get_contents().The problem is that it can read file with http protocol but cannot read file with https protocol.

Please help me out ...

Thanks in advance..

A: 

file_get_contents() should work fine, sounds like your PHP doesn't have SSL support.

Alex Howansky
A: 

Problem is you need to authenticate. Use this:

// connection settings
$ftp_server="ipadress";
$ftp_user_name="username";
$ftp_user_pass="password";

// connect
$conn_id = ftp_ssl_connect($ftp_server); 

// login
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass); 

// check connection
if ((!$conn_id) || (!$login_result)) { 
         echo "ftp-connection failed!<br>";
         echo "connect with $ftp_server using $ftp_user_name not successfull<br>"; 
         die; 
     } else {
         echo "connect witht $ftp_server using $ftp_user_name<br>";
     }

  $list=ftp_nlist($conn_id, $path);

  foreach ($list as $file) {
     echo $file.'<br>';
}

// close ftp stream
ftp_quit($conn_id); 

EDIT: You need to have your server running with the FTP and OpenSSL in order to be able to use ftp-ssl-connect (description from php.net here).

Thariama
This is giving me the error. Call to undefined function 'ftp_ssl_connect()'..what i need to do?
Joy
The question specifically says HTTPS, not FTP.
Matthew Flaschen
@Matthew: I showed him another way of getting the desired information from the https server - and that is what he wanted (you only juged and provided no answer at all).
Thariama
@Thariama, I don't think it's helpful to tell him to set up FTP, when he wants to access HTTPS URLs. You don't know whether he could install FTP even if he wanted to. He never said he was accessing his own servers.
Matthew Flaschen
@Matthew: That is right, but he never stated otherwise. In case he has no access to the servers i think curl is the way to go.
Thariama
+1  A: 

Use the cURL extension.

$url = "https://www.example.com/";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$html_content = curl_exec($ch);
curl_close($ch);
Jeff Standen