1

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

1
  • What version of PHP do you have? It should work with file_get_contents since 4.3.0. An alternative is curl. Commented Sep 24, 2010 at 15:43

3 Answers 3

3

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

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

0

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

5
  • This is giving me the error. Call to undefined function 'ftp_ssl_connect()'..what i need to do?
    – Joy
    Commented Sep 24, 2010 at 16:12
  • 1
    The question specifically says HTTPS, not FTP. Commented Sep 24, 2010 at 19:41
  • @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
    Commented Sep 27, 2010 at 5:56
  • 1
    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. Commented Sep 27, 2010 at 6:14
  • @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
    Commented Sep 27, 2010 at 6:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.