MyBB Community Forums

Full Version: Using api on Header
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wont to use an opensource api from need for speed world on my header.
The api page is here : http://world.needforspeed.com/SpeedAPI/d...irect.html

the code I have for a single php is :

<?php
class Parser {  
    
  var $status;  
  var $xml_parser;  
  var $tagname;  
    
  function parser()  
  {  
    $file = "http://world.needforspeed.com/SpeedAPI/ws/game/1.0/nfsw/server/status";  
    $this->xml_parser = xml_parser_create();  
    xml_set_object($this->xml_parser,$this);  
    xml_set_element_handler($this->xml_parser, "startElement", "endElement");  
    xml_set_character_data_handler($this->xml_parser, 'elementContent');  
    if (!($fp = fopen($file, "r"))) {  
      die("Unable to read status");  
    }  
    
    while ($data = fread($fp, 4096)) {  
      $data=eregi_replace(">"."[[:space:]]+"."<","><",$data);  
      if (!xml_parse($this->xml_parser, $data, feof($fp))) {  
        die(sprintf("XML error: %s at line %d",   
        xml_error_string(xml_get_error_code($this->xml_parser)),  
        xml_get_current_line_number($this->xml_parser)));   
      }  
    }  
  xml_parser_free($this->xml_parser);  
  }  
    
  function startElement($parser, $name, $attrs) {  
    $this->tagname=$name;  
  }  
    
  function elementContent($parser, $data) {  
    switch ($this->tagname)  
    {  
      case 'STATUS' :  
        $this->status=trim($data);  
        break;  
    }  
  }  
  function endElement($parser, $name){  
  $this->tagname=="";  
  }  
}  
  
$p = new Parser();  
if ($p->status == "UP") {   
  echo "The Need For Speed World servers are up and running!";  
}  
elseif($p->status == "DOWN") {   
  echo "The NFS World servers are currently down!";   
}  
else {  
  echo "Red light! Something went terribly wrong.";  
}  
?>


how can I show this single line "The Need For Speed World servers are up and running!" or down whatever. in my header next to the clock ?

simple method could be to use iframe html code for embeding that php file in header template !!