Xbox 360 Gamercard WordPress Plugin
I’ve put together a WordPress plugin that will display a customizable XHTML and CSS Xbox 360 gamer card. There are plenty of sites out there that will make good looking gamer cards using image files, but this method will give you complete control over the appearance. It also acts like a gamer card, with a link to your Xbox Live profile and “compare to” links to your five most recently played games, something the image file cards can’t do.
For those of you who want a raw PHP script with the same functionality, I’ve included one farther down in the post.
How the plugin works
The plugin uses cURL, a command line tool for transferring files with URL syntax, to read the contents of your Xbox Live gamer card from http://gamercard.xbox.com/YOURTAG.card into a string, and then uses the PHP function preg_match to perform regular expression matching on that string. The various elements of your gamer card are extracted and then assigned to variables for later output.
The plugin attempts to create a unique text file for each gamertag (gamercard_cache_YOURTAG.txt) for use as a cache in your blog’s root folder automatically. This is done to reduce the number of times the target HTML page must be accessed and parsed and therefore reduce server load and page load time. Some server configurations may not permit the plugin to create this file and you’ll see resultant errors; in this case, you may have to upload a file with that name and perhaps set permissions on the file. You can edit the plugin to adjust how old the cache can grow before the script refreshes the information from gamercard.xbox.com.
Usage
The plugin accepts two arguments: the first is your gamertag; the second, which is optional, toggles whether the recently played games are displayed.
Insert the code:
<?php if (function_exists('gamercard')) gamercard('YOURTAG'); ?>
into a template file wherever you want the gamer card to appear, replacing YOURTAG with your actual Xbox Live gamertag, ex.:
<?php if (function_exists('gamercard')) gamercard('ardamis'); ?>
You can include multiple, different gamer cards on each page.
Customization
To show the recently played games icons, add the “full” argument, ex.:
<?php if (function_exists('gamercard')) gamercard('ardamis', full); ?>
Do whatever you want with the CSS to integrate the gamer card into your site.
Installation
The download includes:
- xbox-gamercard.php (put this in your /plugins/ directory)
- gamercard.css (copy and paste the contents into your theme’s style.css)
- /gc_images/ (optional – put this folder of reputation images in your WordPress theme’s /images/ folder if you want to use them)
The plugin by default now uses the gold stars with transparent background from the ‘mini-card’ in the top navigation of http://www.xbox.com/. The rep image is a transparent .png, however. If you’re worried that people using IE6 will see an ugly rep because of IE6’s lack of support for transparent .png, you may want to edit the plugin to use a different rep image. It’s easy.
a screen shot of the ‘mini-card’ from Xbox.com
The optional ‘gc_images’ folder contains 20 images, one for each reputation rank, to replace the default gamercard gauge. They are based on the gauge used in the smaller, menu bar gamercard on the old http://live.xbox.com/ site, but with transparent backgrounds instead of gray for greater flexibility. You don’t need to use these, of course. I’ve written 3 variables into the plugin if you want to use the official Xbox rep images. Just edit the plugin to replace $navgamerrep in the output with one of the other variables. (Seriously, it’s easy.)
Download (beta 1.3)
Get the files here:
Download the Xbox 360 Gamer Card WordPress Plugin
I’m getting an error message
If your server does not have cURL enabled, you’ll get an error message that reads something like Fatal error: Call to undefined function curl_init() in PATH\wp-content\plugins\xbox-gamercard.php on line 54. The best solution is to ask your host to enable cURL. If that option is unavailable, I’ve provided an alternative that uses the function file_get_contents(), but a number of hosts have disabled the URL retrieving capabilities in file_get_contents() for security reasons. Download the FGC Gamer Card WordPress Plugin only if you’re getting an error message with the regular download.
Can I get this as a WordPress Widget?
Honestly, the plugin is much more flexible than a widget. Widgets are limited to your sidebar, while the plugin can be used in any template. Installing the plugin isn’t very complicated, either. So, in short, there are no plans to adapt this as a widget right now.
How can I use this on a non-WordPress site?
Download the Xbox 360 Gamer Card Stand-alone Script
Just PHP include the xbox-gamercard-standalone.php script wherever you want the card to be displayed, adjusting the path to the reputation images. Add the contents of gamercard.css to your main CSS file, and modify to suit your site.
Be aware that message boards and forums (eg: vBulletin forums) won’t allow you to use PHP as part of your post or signature. In short, don’t expect this method to work anywhere but on your own site.
You can either edit the script to use your gamertag, or call the script with the line:
<?php include 'PATH-TO-SCRIPT/xbox-gamercard-standalone.php?tag=YOURTAG'; ?>
To show the recent games, use:
<?php include 'PATH-TO-SCRIPT/xbox-gamercard-standalone.php?tag=YOURTAG&full=full'; ?>
Obviously, you’ll replace ‘YOURTAG’ with your gamertag. If you have any spaces in your gamertag, replace each space with %20.
Further customization (optional)
A number of neat image and Flash sigs contain way more information than just what’s provided at http://gamercard.xbox.com/YOURTAG.card, but as far as I can tell, it’s all gathered in the same way. If there’s something you’d like added to the script, find a page that contains the information and post a comment about it, or give programming a shot yourself…
View the source code of the target page and locate the data you wish to extract. What we want to do is identify everything but the desired data. Isolate the desired data within the source code of the target page by copying everything from the first character before the data back to and including something unique, such as a div’s id. Paste that into a preg_match line as the first half of the pattern that the script will look for. Follow that with the characters (.+?), a bit of code that represents the data we want to extract. Do not copy the actual desired data from the target page into the modified script. Last, select and copy a few characters immediately after the data, such as the closing div, and paste that after the (.+?). Everything in between the two copied strings—the stuff now represented by the (.+?) characters—will be assigned to a variable.
Credits
Thanks to Constantin Hofstetter for getting me started on this project and to Jeremy at 360gamerCards.com for eliminating the need for the Snoopy script, reducing the process to a single file and otherwise greatly simplifying the whole thing. And thanks to everyone who emailed or posted with error messages and other problems; it’s a better, more robust plugin because of your efforts.
My gamertag is ardamis, should you want to add me to your friends list and give me some positive feedback.












I had to create gamercard_cache_tag.txt and place it in the blog root myself, otherwise it threw up a load of errors. Did you mean to leave it upto the user to create the file? Might want to stick that in the instructions if you did
April 9th, 2007
Thanks for pointing this out, Dan.
There will be some server configurations that don’t allow the plugin to create the cache file. In these situations, yes, you’ll have to create and upload an appropriately named text file. I’ve edited the post to reflect this.
April 10th, 2007
For those who want to display their gamercard in the sidebar there is a way to do it - check out my tutorial at http://mordani.com/blogs/rohit/...
Edit: Rohit is referring to including a third-party image file gamer card via a WordPress widget
April 12th, 2007
Excellent plugin! I’m glad someone has made a gamercard plugin that’s not for sidebar widgets. Sidebar widgets/modules suck.
April 24th, 2007
I am having a problem with the plugin. I uploaded everything an after putting the code in e.g. sidebar.php i get this:
Fatal error: Call to undefined function curl_init() in /mnt/am2/06/736/00000000/htdocs/blog/wp-content/plugins/xbox-gamercard.php on line 54
May 21st, 2007
A “Fatal error: Call to undefined function curl_init()” message means that your server doesn’t have cURL enabled.
Create a file called phpinfo.php that contains the following code:
Upload it to your site and load it in a browser. You should see a section called “curl” and within that an indication that CURL Support is Enabled. If you don’t see this, then you can ask your hosting company to enable it.
May 22nd, 2007
Is there any chance of having this work locally? Live is ok, but locally i get an error:
Fatal error: Call to undefined function curl_init() in C:\xampplite\htdocs\wordpresstest\wp-content\plugins\xbox-gamercard.php on line 54
May 26th, 2007
If you’re using XAMPP Lite, you could step up to the full version, which I believe supports cURL out-of-the-box. But I’ve updated the post to add an alternative plugin that uses the function file_get_contents() instead of cURL.
May 26th, 2007
thanks, working fine for me
June 2nd, 2007
Looks good! I’m glad you’ve gotten some use out of my changes! I’m working on a Leaderboard script right now, so shoot me an email if you’re interested. I’ve been working alot on an overhaul for 360gamercards.com to turn it into a community site using Dragonfly CMS, so I will be releasing a beta module for that which should be easily portable over to PHP/POST/Whatever-Nuke. I also have a basic script that can be used on any site. Generally for best functionality a database should be used for storing the gamertags you want on the leaderboard, etc, but I am going to integrate some config variables in the script to utilize a list in the script instead.
August 29th, 2007
The plugin is great! Thank you
But there’s one minor problem: It doesn’t update the gamerscore and “played games” every hour (I installed the plugin with your default options). Is this a known problem/bug?
September 2nd, 2007
Whoops. Nice catch, Martin. I had put an extra zero in the timeout. It was refreshing the cache every 10 hours, instead. It’s fixed now.
September 2nd, 2007
Is this still working? I have issues with it but it may be with my server more than anything. cURL is enabled, but when I run it the gamercard cache file only gets the hard coded fields such as time, $tag populated. All the lines that are supposed to be retrieved from xbox.com are blank???
September 16th, 2007
Hey I would like to get your thoughts on this ardamis, over at http://www.mygamercard.net they have a new gamercard with a small icon in the upper corner that shows wheater or not the user is on Xbox LIVE or offline and if they are offline for how long. What do you think the possibility is to add something like this to your mod.
I know a very little about php, I took what you have done here and made two joomla mods for my site one for a login sig if the user is logged in it will show them there card and the other is a who’s online card that shows a small card for each member on our website. But it would be great if when you went to the members section of the site or if they are on our website it would also show if they are on LIVE or not.
What do you think ardamis?
October 7th, 2007
is there any info on the previous post, i was trying to get xboxlive current status included and outputed by the script/plugin but to no joy, and possibly motto.. thanks for any help… great plugin btw thanks
October 8th, 2007
I’ll look into adding an online/offline indicator. Can you point me to a publicly accessible page that has your online/offline status? I know the info is available if you are signed into the Xbox Live site, but I don’t know where to find it without signing in.
October 9th, 2007
well i an online/offline status can be found here http://live.xbox.com/en-GB/profile/profile.aspx?pp=0&GamerTag=ardamis
but for some reason if i replace your tag with mine i dont get that option(but then again why would you want to look at your own status. i did try to includ it myself but iam a n00b with this.
i tried this
preg_match(’#(.+?)#’,$in, $status1);
thanks
hoticeuk
October 9th, 2007
oops didnt work sorry
preg_match('#<h4 class="XbcLiveText">(.+?)</h4></td>#',$in, $status1);October 9th, 2007
Hey ardamis,
How does this plugin get the data? Is it looking at images? I have been looking at the code trying to find out where it’s pulling the data from it’s over my head, I’m a graphic designer, I’m shit at coding lol. If this code is looking to images for data could we use the images from bungie’s site to query whether or not a user is online or off line?
h**p://www.bungie.net/images/FriendIconOnline.gif
h**p://www.bungie.net/images/FriendIconOffline.gif
October 13th, 2007
Great script! I’m using the standalone version and just wondering if it’s possible to modify it to display the smaller (32×32) gamer tile? Also, is there any reason why I wouldn’t get the recently played games icons? I have forced the ‘full’ setting. Thanks.
October 13th, 2007
Presto-X: the plugin gets the code of the entire page at http://gamercard.xbox.com/ardamis.card (your gamercard), then pulls out various useful lines.
It can get the code from any publicly accessible page. The problem is that there doesn’t seem to be any such publicly accessible page that contains a gamer’s Xbox Live online/offline status.
Simply having the path to an image doesn’t help us determine anything - we would need a page that includes that path only under certain circumstances.
island76: There should be a way to use the 32×32 image. I’ll look into it. I’ll also make sure the full setting works for me.
October 13th, 2007
i found Gamercad-Lib on sourceforge. this works the same way as yours with preg_match and cURL this script displays current status, which gets its info from
("http://live.xbox.com/es-ES/profile/profile.aspx?pp=0&GamerTag=". $tag);i hope this helps, i tried to integrate part of their code into yours but no joy.October 14th, 2007
Hey hoticeuk thanks for the info, although the script is suspect lol it asks for your XBOX Live email and password hmmm I’m going to look at the code to make sure it’s not emailing that info home. That would suck! lol I have seen that done with World of Warcraft php website addons NOT cool at all. The thing I like about ardamis system it’s very clean coding and uses only one php file not 3. Great work ardamis!
October 14th, 2007
hehe i couldnt agree more ardamis is the best script for a gamercard i have seen, good for integrating into a website, i never tried to run the script from sourceforge i quickly read through the code, looking for the target page for info. thanks for the heads up.
October 15th, 2007
Hey hoticeuk, the code from Gamercad-Lib looks legit but it would not work on my server setup
I’m going to look at their code and see how they got the other features working.
October 15th, 2007
yeh i have tried tweaking their code but was also unable to get it to work on my setup. their coding is more complex and abit out of my league, good luck let me know if anyone figures this one out admin@hotfrost.org
October 15th, 2007
ardamis, great plugin!
hoticeuk was right. If you go to http://live.xbox.com/en-US/profile/profile.aspx?pp=0&GamerTag=GAMERTAG and replace GAMERTAG with a real tag the page shows if the person is online. If the person is offline it doesn’t show anything however. I might have to mess around and see if I can scrape the status out for use with your script!
October 26th, 2007
[...] Xbox 360 Gamercard by Oliver Baty for the ‘Trophy Fish’ in the footer [...]
November 12th, 2007
Can someone please help!
I get this problem:
Warning: fopen(./gamercard_cache_MASTERBEEF77.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 70
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 71
Warning: file(./gamercard_cache_MASTERBEEF77.txt) [function.file]: failed to open stream: No such file or directory in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 73
Warning: array_map() [function.array-map]: Argument #2 should be an array in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 74
Warning: fopen(./gamercard_cache_MASTERBEEF77.txt) [function.fopen]: failed to open stream: Permission denied in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 99
Warning: fwrite(): supplied argument is not a valid stream resource in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 100
Warning: fclose(): supplied argument is not a valid stream resource in /var/www/vhosts/fokbob.nl/subdomains/jamie/httpdocs/wp-content/plugins/xbox-gamercard-fgc.php on line 101
November 15th, 2007
It looks like your server doesn’t allow the plugin to read from and write to the cache text file. When I have some time, I’ll make a version that doesn’t use a cache.
November 16th, 2007
Ah, fantastic plugin! I didn’t want a gaudy image, and this was just what I needed.
However, for your plugin version for servers that have CURL disabled, the image paths for the xbox rep aren’t working anymore. XBOX has changed them, and it results in a 404.
I ended up changing it in the php file itself, but figured I’d let you know about it to fix it so it will work fine for others.
November 18th, 2007
I think I’ve fixed both versions of the plugin. Thanks.
November 18th, 2007
Ahh this is just what I was looking for, plus it comes in wordpress flavour as an added bonus. I already have my gamertag on my site, but I think i would prefer using this code. great plugin ardamis.
December 1st, 2007
Hi and thx for this plugin:) This is what i need.
But how can i change the size or the number of the playedgames images?
March 6th, 2008
Hi Ardamis,
I was wondering if there is a way to get the current game or most current game played.
March 7th, 2008
Very good job man ;).
Great plugin ardamis.
March 8th, 2008
cheesus: The played games images and links are taken from the gamercard as a single line of code, so there’s no easy way to configure the plugin to selectively display X number of images. However, you could probably edit the plugin to put a div element around the images, then use CSS to give that div a fixed width and height and give the overflow declaration a value of hidden. By adjusting the spacing before and between the images, you could probably push some of them outside the div, and in doing so, hide them from view.
William: The plugin could be edited to display any information that is publicly available - in other words, information that you can see without logging into your Xbox Live account at http://www.xbox.com. Lots of information, like online/offline status, is only visible after you’ve logged in. For security reasons, I’m not going to make the plugin log anyone in.
March 9th, 2008
Great plugin, thank you!
But I noticed it doesn’t get displayed correctly in Opera.
Maybe you could take a look into this.
Thanks again, great work!
March 25th, 2008
Hmmm. It looks fine to me in Opera. I’d be happy to tweak the CSS if you can get me a screenshot.
March 26th, 2008
[...] the image or flash in your web site and it’ll display in real time. There’s also a WordPress plugin that uses a slightly hacky method of using regular expressions on the official Xbox [...]
March 31st, 2008
I got it working fine in Firefox, also seemed to appear fine in Opera!
April 13th, 2008
Hi there I just wanted to say thanks for this plugin, and that it works fine for me.
Cheers!
May 15th, 2008
I’m having the same problem as Jamie above - I’ve tried creating a blank text file in the blog root called gamercard_cache_tag.txt but that doesn’t help either
The gamer card loads ok right at the bottom but how do I fix those errors? Any suggestions? Cheers.
May 18th, 2008
[...] got a nice new widget in my sidebar that displays my Gamertag details, it’s simply called the Xbox 360 Gamercard Wordpress plugin. It doesn’t come as a widget, so I’m using another plugin to use it as a widget, [...]
June 4th, 2008
yey! this is awesome! thanks!
July 7th, 2008