I am getting the following problem when I am trying to open a socket connection to a web server:
[fand@ondine lyrics]$ telnet lyricsspot.com 80
Trying 64.191.54.225...
Connected to lyricsspot.com.
Escape character is '^]'.
get /updates.php HTTP/1.1
Host: [url]www.lyricsspot.com[/url]
HTTP/1.1 200 OK
Date: Mon, 07 Apr 2003 15:37:12 GMT
Server: Apache/1.3.27 (Unix) mod_log_bytes/1.2
mod_bwlimited/1.0 PHP/4.3.1 FrontPage/5.0.2.2510
mod_ssl/2.8.12 OpenSSL/0.9.7a
X-Powered-By: PHP/4.3.1
Transfer-Encoding: chunked
Content-Type: text/html
Connection closed by foreign host.
However, if you go to http://www.lyricsspot.com/updates.php you can clearly see it does exist...
The code is essentially this (grabbed from php.net under fread):
$GrabURL = "/updates.php";
$sockhandle = fsockopen("www.lyricsspot.com", 80, &$errno, &$errstr);
if(!$sockhandle) {
print "server not available!";
} else {
$request = "GET $GrabURL HTTP/1.1\r\n";
$request .= "User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows 98)\r\n";
$request .= "Host: www.lyricsspot.com\r\n";
$request .= "Connection: Close\r\n\r\n";
fputs($sockhandle, $request);
$line = fgets($sockhandle, 1024); //Request Method
$line = fgets($sockhandle, 1024); //Close Method
$line = fgets($sockhandle, 1024); //Server Type
$line = fgets($sockhandle, 1024); //Date
$line = fgets($sockhandle, 1024); //Transfer-Encoding
$line = fgets($sockhandle, 1024); //Content-Type
$line = fgets($sockhandle, 1024); //Cache-control
$line = fgets($sockhandle, 1024); //Set-Cookie
$line = fgets($sockhandle, 1024); //End Header "space"
$content = "";
while (!feof($sockhandle)) {
$line = fgets($sockhandle, 1024); //Packet length
$length = hexdec($line);
$content .= fread($sockhandle, $length); //Packet data
}
print $content;
}
fclose($sockhandle);
Any suggestions??
k.