Socket Question
Posted: Tue Jan 20, 2009 5:34 pm
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];
}
?>