Page 1 of 1

Socket Question

Posted: Tue Jan 20, 2009 5:34 pm
by Whear
Was trying to access a game website to retrieve data from a page. I can't seem to manage to get the socket to load the data from a web page. Thanks for your help in advance.

Code: Select all

<?php
 
$host = "hiscore.runescape.com";
$fp = fsockopen($host, 80, $errno, $errdesc) or
die("Connection to $host failed");
 
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: hiscore.runescape.com\r\n";
    $out .= "Connection: Close\r\n\r\n";
 
$page = array();
fputs($fp, $out);
while(!feof($fp)){
$page = fgets($fp, 1024);
}
 
fclose($fp);
echo "The server returned ".(count($page)).
" Lines";
 
for($i=0; $i < count($page); $i++){
echo $page[$i];
}
 
?>

Re: Socket Question

Posted: Tue Jan 20, 2009 6:03 pm
by it2051229
unless the server is listening to socket port 80.... wait ... HTTP is for 80...or the server doesn't listen to socket connections

Re: Socket Question

Posted: Tue Jan 20, 2009 6:05 pm
by Burrito
change:
$page = fgets($fp, 1024);
to:
$page[] = fgets($fp, 1024);

inside your while loop.

Re: Socket Question

Posted: Tue Jan 20, 2009 8:55 pm
by Whear
I looked at the code of another program similar to what I wanted and found my mistake (although you two helped with toher not related problems).

Anyways, my issue was with the lines 7-9, they should of been:

Code: Select all

   $out = "GET /index_lite.ws?player=zezima HTTP/1.1\r\n";
    $out .= "Host: hiscore.runescape.com\r\n";
    $out .= "Connection: Close\r\n\r\n";