Hi, I tried connecting to my own server using fsockopen but it returns:
HTTP/1.1 406 Not Acceptable Date: Sun, 11 Jul 2004 11:04:35 GMT Server: Apache Connection: close Transfer-Encoding: chunked Content-Type: text/html; charset=iso-8859-1 f7 Not Acceptable An appropriate representation of the requested resource / could not be found on this server.
my php reads
<?php $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?>
<?php $fp = fsockopen("www.example.com", 80, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)<br />\n"; } else { $out = "GET / HTTP/1.1\r\n"; $out .= "Host: www.example.com\r\n"; $out .= "Connection: Close\r\n\r\n";
fwrite($fp, $out); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } ?>
any idea as to why and solution? thank you.
are you running that on your local machine or on the server. If you're running it on your ocal machine there is probably a problem with the time setting on your local machine.
Hi,
if I see things right, you want to get the contents of a page on your server.
You can use file() or fopen() depending on the PHP configuration. Another more powerful solution is to use the curl functions of PHP if your PHP installation supports curl.
Thomas
hi. what i wanted to do, is to check the filesize of a file on another server,
since fsockopen is not ok, how do I go about doing that? is curl capable of doing that?
also, I suspect it's something wrong with my apache config?
you can do that with curl_getinfo.
http://de2.php.net/manual/en/function.curl-getinfo.php
There is one comment on that page that deals with the return codes of a server. If you modify this code a bit to read out download_content_length instead of http_code it should work. download_content_length will contain the Content-Length that the web server returns.