dflow Posted June 22, 2011 Share Posted June 22, 2011 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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/240125-fsockopen-correct-use/ Share on other sites More sharing options...
fugix Posted June 22, 2011 Share Posted June 22, 2011 Change this while (!feof($fp)) { $data=true; $line=fgets($fp,128); To while ($line = fgets($fp,128)) { $data=true; Quote Link to comment https://forums.phpfreaks.com/topic/240125-fsockopen-correct-use/#findComment-1233405 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.