Jump to content

File Get Contents Error.


ajicles

Recommended Posts

I am trying to parse a file (http://radio.zybez.net:8000/7.html) and I use:

echo file_get_contents("http://radio.zybez.net:8000/7.html");

 

And I get this error back:

Warning: file_get_contents(http://radio.zybez.net:8000/7.html) [function.file-get-contents]: failed to open stream: HTTP request failed! ICY 404 Resource Not Found in D:\wamp\www\Radio\testttt.php on line 3

 

I do not have access to the server or files I just want to make a song history system for my own ShoutCast Radio Server. I was looking around and some people were saying the robots function of a web-server was not allowing file_get_contents access to that file.

Link to comment
https://forums.phpfreaks.com/topic/207085-file-get-contents-error/
Share on other sites

I don't have access to the server. But I was looking around and found I could use a xml parser, but it was written for PHP 4.

 

<?php

//error_reporting (E_ALL ^ E_NOTICE);

class SCXML {

  var $host="68.168.98.191"; 
  var $port="13511"; 
  var $password="*********"; 

  var $depth = 0;
  var $lastelem= array();
  var $xmlelem = array();
  var $xmldata = array();
  var $stackloc = 0;

  var $parser;

  function set_host($host) {
    $this->host=$host;
  }

  function set_port($port) {
    $this->port=$port;
  }

  function set_password($password) {
    $this->password=$password;
  }

  function startElement($parser, $name, $attrs) {
    $this->stackloc++;
    $this->lastelem[$this->stackloc]=$name;
    $this->depth++;
  }

  function endElement($parser, $name) {
    unset($this->lastelem[$this->stackloc]);
    $this->stackloc--;
  }

  function characterData($parser, $data) {
    $data=trim($data);
    if ($data) {
      $this->xmlelem[$this->depth]=$this->lastelem[$this->stackloc];
      $this->xmldata[$this->depth].=$data;
    }
  }

  function retrieveXML() {
    $rval=1;

    $sp=@fsockopen($this->host,$this->port,$errno,$errstr,10);
    if (!$sp) $rval=0;
    else {

      stream_set_blocking($sp,false);


      fputs($sp,"GET /admin.cgi?pass=$this->password&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");

      // if request takes > 15s then exit

      for($i=0; $i<30; $i++) {
    if(feof($sp)) break; // exit if connection broken
    $sp_data.=fread($sp,31337);
    usleep(500000);
      }


$domain = strstr($sp_data, '<SONGTITLE>');

$user = strstr($domain.' ', '</SONGTITLE>', true); // As of PHP 5.3.0

$data = str_replace("<SONGTITLE>", "", $user);
/*
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("shitty", $con);

$result = mysql_query("SELECT * FROM lastplayed", $con);
$num_rows = mysql_num_rows($result);
$ID = $num_rows + 1;  
$check = "SELECT shitty(*) FROM lastplayed WHERE song_played='$data')";
$checked = mysql_query($check, $con);
$result = mysql_fetch_row($checked);
$result = $result['0'];

$sql="INSERT INTO lastplayed(ID, song_played) VALUES ('$ID','$data')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

if($result >0)
{
echo ('Exists');
}
else
{
$sql="INSERT INTO lastplayed(ID, song_played) VALUES ('$ID','$data')";
}	 
  */


      $this->parser = xml_parser_create();
      xml_set_object($this->parser,$this);
      xml_set_element_handler($this->parser, "startElement", "endElement");
      xml_set_character_data_handler($this->parser, "characterData");

      if (!xml_parse($this->parser, $sp_data, 1)) {
    $rval=-1;
      }

      xml_parser_free($this->parser);

    }
    return $rval;
  }

  function debugDump(){
    reset($this->xmlelem);
    while (list($key,$val) = each($this->xmlelem)) {
      echo "$key. $val -> ".$this->xmldata[$key]."\n";
    }

  }

  function fetchMatchingArray($tag){
    reset($this->xmlelem);
    $rval = array();
    while (list($key,$val) = each($this->xmlelem)) {
      if ($val==$tag) $rval[]=$this->xmldata[$key];
    }
    return $rval;
  }

  function fetchMatchingTag($tag){
    reset($this->xmlelem);
    $rval = "";
    while (list($key,$val) = each($this->xmlelem)) {
      if ($val==$tag) $rval=$this->xmldata[$key];
    }
    return $rval;
  }

}

?>

 

I am still working on this script to display last played songs. I was thinking to put it into a database. I still thinking of other ways to do this.

I don't have access to the server. But I was looking around and found I could use a xml parser, but it was written for PHP 4. But fixed any error messages.

 

<?php

//error_reporting (E_ALL ^ E_NOTICE);

class SCXML {

  var $host="68.168.98.191"; 
  var $port="13511"; 
  var $password="*********"; 

  var $depth = 0;
  var $lastelem= array();
  var $xmlelem = array();
  var $xmldata = array();
  var $stackloc = 0;

  var $parser;

  function set_host($host) {
    $this->host=$host;
  }

  function set_port($port) {
    $this->port=$port;
  }

  function set_password($password) {
    $this->password=$password;
  }

  function startElement($parser, $name, $attrs) {
    $this->stackloc++;
    $this->lastelem[$this->stackloc]=$name;
    $this->depth++;
  }

  function endElement($parser, $name) {
    unset($this->lastelem[$this->stackloc]);
    $this->stackloc--;
  }

  function characterData($parser, $data) {
    $data=trim($data);
    if ($data) {
      $this->xmlelem[$this->depth]=$this->lastelem[$this->stackloc];
      $this->xmldata[$this->depth].=$data;
    }
  }

  function retrieveXML() {
    $rval=1;

    $sp=@fsockopen($this->host,$this->port,$errno,$errstr,10);
    if (!$sp) $rval=0;
    else {

      stream_set_blocking($sp,false);


      fputs($sp,"GET /admin.cgi?pass=$this->password&mode=viewxml HTTP/1.1\nUser-Agent:Mozilla\n\n");

      // if request takes > 15s then exit

      for($i=0; $i<30; $i++) {
    if(feof($sp)) break; // exit if connection broken
    $sp_data.=fread($sp,31337);
    usleep(500000);
      }


$domain = strstr($sp_data, '<SONGTITLE>');

$user = strstr($domain.' ', '</SONGTITLE>', true); // As of PHP 5.3.0

$data = str_replace("<SONGTITLE>", "", $user);
/*
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("shitty", $con);

$result = mysql_query("SELECT * FROM lastplayed", $con);
$num_rows = mysql_num_rows($result);
$ID = $num_rows + 1;  
$check = "SELECT shitty(*) FROM lastplayed WHERE song_played='$data')";
$checked = mysql_query($check, $con);
$result = mysql_fetch_row($checked);
$result = $result['0'];

$sql="INSERT INTO lastplayed(ID, song_played) VALUES ('$ID','$data')";
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

if($result >0)
{
echo ('Exists');
}
else
{
$sql="INSERT INTO lastplayed(ID, song_played) VALUES ('$ID','$data')";
}	 
  */


      $this->parser = xml_parser_create();
      xml_set_object($this->parser,$this);
      xml_set_element_handler($this->parser, "startElement", "endElement");
      xml_set_character_data_handler($this->parser, "characterData");

      if (!xml_parse($this->parser, $sp_data, 1)) {
    $rval=-1;
      }

      xml_parser_free($this->parser);

    }
    return $rval;
  }

  function debugDump(){
    reset($this->xmlelem);
    while (list($key,$val) = each($this->xmlelem)) {
      echo "$key. $val -> ".$this->xmldata[$key]."\n";
    }

  }

  function fetchMatchingArray($tag){
    reset($this->xmlelem);
    $rval = array();
    while (list($key,$val) = each($this->xmlelem)) {
      if ($val==$tag) $rval[]=$this->xmldata[$key];
    }
    return $rval;
  }

  function fetchMatchingTag($tag){
    reset($this->xmlelem);
    $rval = "";
    while (list($key,$val) = each($this->xmlelem)) {
      if ($val==$tag) $rval=$this->xmldata[$key];
    }
    return $rval;
  }

}

?>

 

I am still working on this script to display last played songs. I was thinking to put it into a database. I still thinking of other ways to do this.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.