Hi all, the following script will get the online status of a xbox360 user <?php $ch = curl_init("http://duncanmackenzie.net/services/Get XboxInfo.aspx?GamerTag=YOURGAMERTAG"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4);; $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXmlElement($data, LIBXML_NOCDATA); foreach ($xml->PresenceInfo as $mystatus) { print '<div id="xboxlivestatus">' . $mystatus->Status Text . ' : ' . $mystatus->Info . ' </div>'; } ?> PHP: What i want is to have this sript run in a form with a simple textbox and submit button. on submit it replaces YOURGAMERTAG with the gamertag typed into the textbox and run the rest of the script. anyone know how to do this ? if you could modify the script for this i would be Thanks Paul
Try adding a form that has a hidden field that tells your PHP script if the form has been submitted or not... Something like this: <?php if ($_POST['runyet'] <> "") { $ch = curl_init("http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=" & $_POST['gamerid']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4); $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXmlElement($data, LIBXML_NOCDATA); foreach ($xml->PresenceInfo as $mystatus) { print '<div id="xboxlivestatus">' . $mystatus->StatusText . ' : ' . $mystatus->Info . ' </div>'; } } ?> <form method="POST" action="thispage.php"> <input type="text" name="gamerid" id="gamerid"> <input type="hidden" name="runyet" id="runyet" value="yes"> <input type="submit" value="Go!"> </form> PHP: This might not work, give me a shout if it doesn't work - you could also add some validation in here to stop people entering nothing in the gamerid box. Let me know how it goes. Sonic
Hi and thanks for the help. Dose not seem to be working have it uploaded at http://www.united-gamerz.com/xboxsc.php i got the script of http://michaelwschultz.com/category/games/ with and these sites might help http://duncanmackenzie.net/Blog/put-up-a-rest-api-for-xbox-gamertag-data http://duncanmackenzie.net/services/XboxInfo.asmx?op=GetXboxInfo Any idea of a working script?
check the line print '<div id="xboxlivestatus">' . $mystatus->StatusText . ' : ' . $mystatus->Info . ' </div>'; PHP: it is supposed to be print '<div id="xboxlivestatus">' . $mystatus->Status Text . ' : ' . $mystatus->Info . ' </div>'; PHP:
now gives error 500- internal server error on submit see http://www.united-gamerz.com/xboxsc.php And thanks for your help
<?php if ($_POST['runyet'] <> "") { $ch = curl_init("http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=" . $_POST['gamerid']); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 4); $data = curl_exec($ch); curl_close($ch); $xml = new SimpleXmlElement($data, LIBXML_NOCDATA); foreach ($xml->PresenceInfo as $mystatus) { echo '<div id="xboxlivestatus">' . $mystatus->StatusText . ' : ' . $mystatus->Info . ' </div>'; } } ?> <form method="POST" action="get.php"> <input type="text" name="gamerid" id="gamerid"> <input type="hidden" name="runyet" id="runyet" value="yes"> <input type="submit" value="Go!"> </form> PHP: This works : http://www.w-a-a.co.uk/get.php
Yes, that works, Thanks. Just one last question, do you have any idea on how to use this code ? what would an example code of using this be? <?php class GamerCard { var $memberType; var $tag; var $rep; var $score; var $zone; var $recentlyPlayed; var $gamerPictureUrl; } function error_handler($errno, $errstr) { } function getGamerCard($gamerTag) { $url = "http://gamercard.xbox.com/" . urlencode($gamerTag) . ".card"; // Grab the gamercard - the card HTML is not valid xml (the base tag is not closed) // but the "body" tag and its contents are a valid xml doc so we throw away the contents of the "head" tag. // We don't need them anyway. // $request = new HTTPRequest($url); // $cardHTML = $request->DownloadToString(); set_error_handler("error_handler"); $cardHTML = file_get_contents($url); restore_error_handler(); if ($cardHTML == false) { return ""; } $tmp = preg_split("/<\/head>/", $cardHTML); $tmp = preg_split("/<\/html>/", $tmp[1]); $cardHTML = preg_replace(array("@<script[^>]*?>.*?</script>@si", "@<noscript[^>]*?>.*?</noscript>@si"), array("", ""), $tmp[0]); // Strip SCRIPT tags - not valid XML $xml = domxml_open_mem("<?xml version='1.0' standalone='yes'?>" . $cardHTML); if (!$xml) { print "Error parsing XML"; exit; } $root = $xml->document_element(); $xpath = $xml->xpath_new_context(); $card = new GamerCard(); $card->tag = $gamerTag; // Membership type (Gold/Silver) $elems = $xml->get_elements_by_tagname("h3"); foreach($elems as $elem) { $class = $elem->get_attribute("class"); if ($class == "XbcGamertagGold") $card->memberType = "Gold"; else if ($class == "XbcGamertagSilver") $card->memberType = "Silver"; } // Gamer picture $obj = $xpath->xpath_eval('//img[@class="XbcgcGamertile"]'); $nodeset = $obj->nodeset; $card->gamerPictureUrl = $nodeset[0]->get_attribute("src"); // Gamerscore $obj = $xpath->xpath_eval('//span[preceding-sibling::span/img[@alt="Gamerscore"]]'); $nodeset = $obj->nodeset; $card->score = $nodeset[0]->get_content(); // Rep $obj = $xpath->xpath_eval('//span[preceding-sibling::span="Rep"]/img'); $nodeset = $obj->nodeset; $url = $nodeset[0]->get_attribute("src"); $tmp = preg_split("/[._]/", $url); $card->rep = $tmp[3]; // Zone $obj = $xpath->xpath_eval('//span[preceding-sibling::span="Zone"]'); $nodeset = $obj->nodeset; $card->zone = $nodeset[0]->get_content(); // Recently Played $obj = $xpath->xpath_eval('//div[@class="XbcgcGames"]//img'); $nodeset = $obj->nodeset; foreach($nodeset as $node) { $card->recentlyPlayed[] = $node->get_attribute("title"); } return $card; } ?> PHP:
I don't have an xBox, but it looks like that's how you would grab information about a users account... How to use it - not sure without playing about a bit... At a glance it looks like you need to set $gamerTag as the gamers ID... Try running that script with: right at the top (just after the opening PHP tag)
nope dosent seam to work, btw an example live user id would be Festive Turkey BTW, with the original script that dose http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=userid to get the information that u got working for me it return what game there playing, or says they were ofline, last seen online on halo wars for example. But the url gives allot of information that is not shown, if you take a look at http://duncanmackenzie.net/services/GetXboxInfo.aspx?GamerTag=Festive+Turkey you will see what i mean, quite allot of info is given. any idea on how to display this info? since this will do the same job once this is working it will be job done and thanks for your help. P.S i just noticed u live in Somerset, i just came back from camping there lol
I can't really spend any more time on this - I have too much to do! Go and have a looka around on google - there are loads of tutorials on parsing XML documents. If you're still having problems then PM me.