Apr
UPDATED: Using the LOTRO Server feed
Posted by MueR as Lord of the Rings Online
Some people had a bit of a hard time getting my server status feed to work properly. So, I’ll add a simple PHP example here.
If you open the feed, you will see it is divided in two main areas: FeedInfo and StatusList. The StatusList block is what we are using, so let’s take a good look at it. Every server is listed within it’s own <Server> block. In this block, you will see two elements, ServerName and ServerStatus. The first requires no explanation I think, the second is a simple boolean value; 1 for online, 0 for offline/unknown.
Now let’s start building some code for it. Remember, this is a quick and dirty version. Improvements can be made on the code, feel free to suggest them in the comments.
<?php
// Let's get the feed
$feed = @file_get_contents('http://muer.nl/lotro/serverstatus2.xml');
if (strlen($feed) == 0) {
echo "Loading feed failed.";
} else {
$serverXML = simplexml_load_string($feed);
foreach ($serverXML->StatusList->Server as $server) {
echo $server->ServerName . ' is ';
echo ($server->ServerStatus == 1 ? 'online':'offline');
echo '<br />';
}
}
?>
Now I’ll leave it to you how you work this into a website. This is the basics. Please do let me know how it turned out.
Update: I’ve added a second version of the XML, it will save you some time parsing it when you want to use a custom display. See http://muer.nl/lotro/serverstatus2.xml for the v2.
11 comments so far
Hello. I just ajusted the code a bit and used in my site. The only problem that i have is that my ISP does not allow “fopen” so i cant “read” the xml file from your site. Is it possible to mail me the code for the xml, so i can place the xml machine in my site?
Thanks
Revealing my secret code? Nah :p What you can do, is use cURL to get the xml file.
A sample:
-
<?php
-
$ch = curl_init();
-
curl_setopt($ch, CURLOPT_URL, 'http://muer.nl/lotro/serverstatus2.xml');
-
curl_setopt($ch, CURLOPT_HEADER, 0);
-
$feed = curl_exec($ch);
-
-
if (curl_errno($ch))
-
echo "Loading server status failed";
-
else
-
{
-
$serverXML = simplexml_load_string($feed);
-
foreach ($serverXML->StatusList->Server as $server) {
-
echo $server->ServerName . ' is ';
-
echo ($server->ServerStatus == 1 ? 'online':'offline');
-
echo '<br />';
-
}
-
}
Whoops, I forgot a curl_close($ch) on the last line.
TY! You r my man. I will check it and will tell u what happen.
Had some progress, my ISP supports cURL, but it seems that the "simplexml_load_string" function returns full string of XML file, but there is no further progress. I have the file still on server if u like to check the result plz visit: http://www.cocs-lotro.com/b.php.
Any suggestions welcome
Hmm. You're printing out the entire XML file. Could you change the extention of that file to phps? That way I can see the actual source. Alternatively, send it to me via email: bas@this domain
-
<?php
-
$ch = curl_init();
-
curl_setopt($ch, CURLOPT_URL, 'http://muer.nl/lotro/serverstatus2.xml');
-
curl_setopt($ch, CURLOPT_HEADER, 0);
-
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
-
$feed = curl_exec($ch);
-
curl_close($ch);
-
-
if (curl_errno($ch))
-
echo "Loading server status failed";
-
else
-
{
-
$serverXML = simplexml_load_string($feed);
-
foreach ($serverXML->StatusList->Server as $server)
-
{
-
echo $server->ServerName . ' is ';
-
echo ($server->ServerStatus == 1 ? 'online':'offline');
-
echo '<br />';
-
}
-
}
-
?>
Try this code
Hmm try these URLs:
http://www.cocs-lotro.com/e.php
http://www.cocs-lotro.com/e.phps
Also
http://www.cocs-lotro.com/f.php
http://www.cocs-lotro.com/f.phps
php info on
http://www.cocs-lotro.com/info.php
It seems after
'$serverXML = simplexml_load_string($feed);'
line, the code stops.
I even tryied to place ----echo "blahblah";---
right before the end of file but it doent show up :/
You need to get your host to update PHP. They're running PHP4, which has been terminated last year. It's an unsafe PHP version. Tell your host to update to PHP5 and everything will work
I thought so, as on my local network with PHP5 all worked fine, i will sent em an e-mail about this.
Anyway tnx for the help, u do great work, keep going
Leave a Comment:
-
Recent posts
Categories
Blogroll
Archive
Recent Comments
Tags
Links