Joy
Joy

Reputation: 1639

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..

Upvotes: 1

Views: 7983

Answers (3)

Thariama
Thariama

Reputation: 50832

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).

Upvotes: 0

Jeff Standen
Jeff Standen

Reputation: 6866

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);

Upvotes: 3

Alex Howansky
Alex Howansky

Reputation: 53563

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

Upvotes: 0

Related Questions