1

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)

Toon Krijthe
  • 52,876
  • 38
  • 145
  • 202
  • There's lots of free hosting out there; why not find one that does? – Jared Farrish Jul 21 '12 at 15:31
  • Sounds like you may need to find another host who allows CURL or `file_get_contents()` access to remote servers. (And maybe suggest to the remote server owners to update their SSL certificate.) – Luke Stevenson Jul 21 '12 at 15:39
  • You might try `wget https://other-server.com`... but it sounds like this particular host doesn't want you to make outbound connections. Find one that allows it. – phatfingers Jul 21 '12 at 15:59

1 Answers1

2

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

Community
  • 1
  • 1
mschr
  • 8,531
  • 3
  • 21
  • 35
  • Thank you for quick answer, but... Nope: `-1219506188 : Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?`. That is the 'ssl transport not available error message', but as I said, I am not able to modify servers config (plus, it has `exec` and `system` disabled, so wget doesn't work either). Many other people will find this sollution usefull, but I will problably find some other freehosting server. Have you got any suggestions? (With freehosting I mean I'm not going to pay anything) –  Jul 22 '12 at 12:24
  • Well, im not going to advertise any services (as im about to start my own :) but a simple google search against "free web hotel" would do the trick, then cycle through until my test-script doesnt throw error. – mschr Jul 22 '12 at 14:55