Jump to content

fsockopen correct use


dflow

Recommended Posts

i need to connect from a server that only allows fsockopen to an external xml link,

 

om using this code from the php mannual

 

i get

:

Unable to retrieve all or part of www.example.com

<?php
$data=false;
$url='www.example.com';

$fp = @fsockopen($url, 80, $errno, $errstr, 1);
if ($fp) {
    stream_set_timeout($fp,1);         
    $out = "GET / HTTP/1.0\r\n";
    $out .= "Host: www.example.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
    if (fwrite($fp, $out)) {
        $content='';
        $header = "not yet";
        while (!feof($fp)) {
            $data=true;
            $line=fgets($fp,128);
            if ($line=="\r\n" && $header=="not yet") {
                $header = "passed";
            }
            if ($header=="passed") {
                $content.=$line;
            }
        }
        fclose ($fp);
    }
}
if (!$data) {
    print "Unable to retrieve all or part of $url";
} else {
    print "$content";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/240125-fsockopen-correct-use/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.