[eluser]Unknown[/eluser]
Hi all, I've knocked up this model to get server stats from a ShoutCast Server:
Code:
<?php
class Radio extends Model {
function Radio () {
parent::Model();
}
function radio_stats ($server,$port) {
// open connection to shoutcast
$fp = fsockopen($server, $port, $errno, $errstr, 1);
if (!$fp)
{
echo "Failed to connect to shoutcast";
exit();
}
//get the 7.html data
fputs($fp, "GET /7.html HTTP/1.0\r\nUser-Agent: Mozilla\r\n\r\n");
// do what it needs to.
while(!feof($fp))
{
$line = fgets($fp, 512);
if ($line == "\r\n")
break;
$line = trim($line);
if (eregi("HTTP", $line))
{
$header['Response'] = ereg_replace("HTTP/1.0 ", "", $line);
}
else
{
$header[ereg_replace(":.*", "", $line)] = trim(ereg_replace(".*:", "", $line));
}
}
//var_dump($header);
while(!feof($fp))
{
$xml_data .= fread($fp, 512);
}
fclose($fp);
$wayhey = explode(",",$xml_data);
return $wayhey;
}
}
?>
I'm new to CodeIgniter, and it all works great. The data is obtained.
Thing is onced its called with:
Code:
print_r ($this->Radio->radio_stats('localhost','8002'));
I get the following error:
Code:
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: xml_data
Filename: models/radio.php
Line Number: 42
But the correct stats still output.
Any ideas? :/