user1080431
user1080431

Reputation:

Fetch file from https only server

I have a small script which uses curl and retrives specific contents from a defined url. I had this tested on my localhost and it worked.

Now I have to retrive data from a HTTPS-only website (plus, the certificate is invalid, but I know the owners) from my free hosting, but the myserver neither supports CURL nor file_get_contents("https://other-server.com") function. By the way, http://other-server.com isn't accesible.

Is there any method to fetch a file from this server using the HTTPS port, but with HTTP protocol? Or is there some method to use HTTPS, altough my server doesn't support it? (It isn't my server, I haven't access to its configuration)

Upvotes: 1

Views: 562

Answers (1)

mschr
mschr

Reputation: 8641

Try this:

<?php
$fp = fsockopen("ssl://other-server.com", 443, $errno, $errstr);
if(!$fp) die($errno. " : " . $errstr);
$send = 
 "GET / HTTP/1.0\r\n".
 "Host:other-server.com\r\n".
 "Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n".
 "\r\n";

fwrite($fp, $send);
while(!feof($fp)) {
  echo fread($fp, 512);
}

?>

Should you run into 'ssl transport not available error message', see Socket transport "ssl" in PHP not enabled

If your host is external and perhaps a free webhosting service, you are fresh out of luck.. Best option would be to figure out which webhosts has the SSL transport enabled - otherwise the working with HTTPS protocol simply will not comply.

Your last 'out' is to try to load extension into PHP language dynamically. You will need the excact extension (dll/so) which matches

  1. the PHP version on host (see phpinfo).
  2. the CPU architechture of host (unix, see passthru("cat /proc/cpuinfo");), e.g. amd64,i386..
  3. the OS 'layout', .dll is for a windows host (IIS etc) and .so for UNIX.

Funcition to use is dl aka dynamic-link to load the library. For windows host, you will need php_openssl.dll and php_sockets.dll - and in turn for UNIX, OOops - you would need to recompile php core..

Happy hacking :)

php-man-pages

Upvotes: 2

Related Questions