|
-
Apr 7th, 2009, 08:26 AM
#1
Thread Starter
Hyperactive Member
how do i . . .
Hi all,
How do i use this script ?
PHP Code:
<?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;
}
?>
bit stuck lol.
would i need a form? what would an example code for the form be?
Thanks
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 10:12 AM
#2
Re: how do i . . .
*edit* after looking at it a bit more, the response was wrong. Still looking into it
Last edited by kfcSmitty; Apr 7th, 2009 at 10:27 AM.
-
Apr 7th, 2009, 10:28 AM
#3
Thread Starter
Hyperactive Member
Re: how do i . . .
 Originally Posted by kfcSmitty
*edit* after looking at it a bit more, the response was wrong. Still looking into it
nope still dossent show anything. uploaded at http://www.united-gamerz.com/xboxlg.php
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 10:56 AM
#4
Re: how do i . . .
Ok, so anyways, this function returns an object with values. It doesn't actually draw the card.
You can access the object's attributes as shown.
Code:
$x = getGamerCard("gamertag");
echo $x->gamerPictureUrl;
The attributes available are:
var $memberType;
var $tag;
var $rep;
var $score;
var $zone;
var $recentlyPlayed;
var $gamerPictureUrl;
If this code is meant to draw the entire card, I have thus far been unsuccessful.
-
Apr 7th, 2009, 11:16 AM
#5
Thread Starter
Hyperactive Member
Re: how do i . . .
 Originally Posted by kfcSmitty
Ok, so anyways, this function returns an object with values. It doesn't actually draw the card.
You can access the object's attributes as shown.
Code:
$x = getGamerCard("gamertag");
echo $x->gamerPictureUrl;
The attributes available are:
var $memberType;
var $tag;
var $rep;
var $score;
var $zone;
var $recentlyPlayed;
var $gamerPictureUrl;
If this code is meant to draw the entire card, I have thus far been unsuccessful.
nope stil dosent work, not shure if its going to.
ive got another working script now, this is a form, that on submishion gets a user id thats in a textbox, it then check a page, and brings back some information. this is what im using.
PHP Code:
<?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>
the information it brings back is limeted. if you go to an example user id, http://duncanmackenzie.net/services/...Festive+Turkey
you will see theres allot of information its offering.
How can i get it to call on all the information?
in <XboxInfo>
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 11:37 AM
#6
Re: how do i . . .
First off, the code I gave you works, so I would need to check your code to find out what's wrong.
As for your second attempt.
The below line
Code:
foreach ($xml->PresenceInfo as $mystatus)
It grabs the "PresenceInfo" node.
Then the below line
Code:
echo '<div id="xboxlivestatus">' . $mystatus->StatusText . ' : ' . $mystatus->Info . ' </div>';
Displays the child nodes within PresenceInfo, with the appropriate names ("StatusText" and "Info"). All names are case sensitive.
So, if you wanted more info from the PresenceInfo node, it would simply be something like
Would give you the "Valid" node value.
If you wanted to get a different parent node, you would need to change or add
Code:
foreach ($xml->XboxUserGameInfo as $mystatus)
to get all of the games and their info. Then once you have that handle, you could get everything within again by doing
-
Apr 7th, 2009, 11:46 AM
#7
Thread Starter
Hyperactive Member
Re: how do i . . .
Thanks for teh help, what if i want something not in a childhood ? for example <AccountStatus>
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 11:50 AM
#8
Re: how do i . . .
Just flat out
Code:
$xml->AccountStatus
Will give you account status.
-
Apr 7th, 2009, 12:13 PM
#9
Thread Starter
Hyperactive Member
Re: how do i . . .
mmm not working for me, whats wrong with this?
PHP Code:
<?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 'User';
echo 'echo '$xml->Gamertag';
}
}
?>
<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>
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 12:43 PM
#10
Re: how do i . . .
What isn't working? Is it not showing anything, is it showing the string literals but not the variables, etc?
Also, why would you need to pull their gamertag out of the XML if they're the ones supplying it?
*edit* Actually, looking at your code, it shouldn't actually render. Do you have errors turned off?
Last edited by kfcSmitty; Apr 7th, 2009 at 12:48 PM.
-
Apr 7th, 2009, 12:58 PM
#11
Thread Starter
Hyperactive Member
Re: how do i . . .
 Originally Posted by kfcSmitty
What isn't working? Is it not showing anything, is it showing the string literals but not the variables, etc?
Also, why would you need to pull their gamertag out of the XML if they're the ones supplying it?
*edit* Actually, looking at your code, it shouldn't actually render. Do you have errors turned off?
no dont think i have them switched of, not sure, dont know how to check, im a bit new to php
and im getting error 500 internal server error
got it uploaded at http://www.united-gamerz.com/get.php
and thanks for the help by the way
use as a example username
Last edited by Paul_so40; Apr 7th, 2009 at 01:02 PM.
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 01:04 PM
#12
Re: how do i . . .
I get nothing when loading that page, just a blank page. A 500 error is a server-side error. Are you running this on a local machine or a paid for webhost? Have you played with your php.ini or anything?
Also, to enable errors on this page only, you can add error_reporting(E_ALL); to the top of the page.
If you want to enable it for all of your pages, then you can change error_reporting and display_errors in your php.ini.
Last edited by kfcSmitty; Apr 7th, 2009 at 01:07 PM.
-
Apr 7th, 2009, 01:10 PM
#13
Thread Starter
Hyperactive Member
Re: how do i . . .
 Originally Posted by kfcSmitty
I get nothing when loading that page, just a blank page. A 500 error is a server-side error. Are you running this on a local machine or a paid for webhost? Have you played with your php.ini or anything?
Also, to enable errors on this page only, you can add error_reporting(E_ALL); to the top of the page.
If you want to enable it for all of your pages, then you can change error_reporting and display_errors in your php.ini.
mm u should be getting a textbox and a submit button saying go
the entire pages source is
PHP Code:
<?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 'User';
echo 'echo '$xml->Gamertag';
}
}
?>
<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>
you only get the error on submit.
and its on a paid host, with no editing to any other files
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 01:13 PM
#14
Thread Starter
Hyperactive Member
Re: how do i . . .
ohhhh - nothing at all displays in firefox, try using i.e
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 01:16 PM
#15
Re: how do i . . .
Doesn't display in IE8 either, but anyways
"The website has a programming error."
Should be a hint for you. Double check your code.
For example:
Code:
echo 'User';
echo 'echo '$xml->Gamertag';
Will break it since you're not concatenating properly. You also have an extra quote at the end. It should be:
Code:
echo 'User';
echo 'echo ' . $xml->Gamertag;
-
Apr 7th, 2009, 01:23 PM
#16
Thread Starter
Hyperactive Member
Re: how do i . . .
mmm showed to me on i.e.8 , but anywayz the
Code:
echo 'User';
echo 'echo ' . $xml->Gamertag;
works, thanks
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 04:34 PM
#17
Thread Starter
Hyperactive Member
Re: how do i . . .
ok, im still confused, the following script is not working. full page source
PHP Code:
<?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 'User ' . $xml->Gamertag;
echo "\n";
echo 'Is currently ' . $xml->PresenceInfo->Info;
}
}
?>
<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>
got it uploaded at http://www.united-gamerz.com/get.php using i.d Festive+Turkey
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 05:04 PM
#18
Re: how do i . . .
If you go to:
http://duncanmackenzie.net/services/...Festive+Turkey
you'll notice that now they're listing much less XML. So your program has nothing to grab. There is no child node Info under PresenceInfo.
One of the many flaws to using someone elses server. The gamercard.xbox.com one seems more professionally run, and if you're intent on using someone elses server to hold the content, I imagine theirs would be more stable.
-
Apr 7th, 2009, 05:12 PM
#19
Thread Starter
Hyperactive Member
Re: how do i . . .
yh mmm, if u can rerember, there was a lot more info given earlier
duno where its all gone lol
Please Rate If I helped you.
Please remember to mark threads as closed if your issue has been resolved.
-
Apr 7th, 2009, 05:14 PM
#20
Re: how do i . . .
 Originally Posted by Paul_so40
yh mmm, if u can rerember, there was a lot more info given earlier
duno where its all gone lol
Yeah, it seems like that info is just hosted on some guys blog. I really wouldn't trust it too much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|