0

I want to read some phrases from an external website which protocol is https. I've do this for websites with http protocol by this code:

$homepage  = file_get_contents('https://www.examlple.com/');
echo $homepage;

but it does not work for https sites. then I used this one:

$fp = fsockopen("https://www.example.com/", 80, $errno, $errstr, 30);
if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, "Data sent by socket");
    $content = "";
    while (!feof($fp)) {  //This looped forever
        $content .= fread($fp, 1024);
    }
   fclose($fp);
   echo $content;
}

but I always get an error:

Unable to find the socket transport "http" - did you forget to enable it when you configured PHP? (2)

actualy the case is to fetch my site's statistics from analytics.

shekoufeh
  • 559
  • 2
  • 5
  • 11

1 Answers1

0

Fsockopen does not know about "http, https". Please remove the http part from your domain and use SSL Port for connection.

See example, this should work:

// open ssl connection - dont add "http or https!"
$host = "ssl://" . "example.com";
$port = 443;
$fp = fsockopen($host,$port);

if (!$fp) {
   echo "$errstr ($errno)<br />\n";
} else {
    fwrite($fp, "Data sent by socket");
    $content = "";
    while (!feof($fp)) {  //This looped forever
        $content .= fread($fp, 1024);
    }
   fclose($fp);
   echo $content;
}
opHASnoNAME
  • 20,224
  • 26
  • 98
  • 143