Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-31-2005, 08:38 PM   PM User | #1
fbelzile
New Coder

 
Join Date: Jun 2005
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
fbelzile is an unknown quantity at this point
Smile Solved: X-Fire Status with PHP

I'm making a clan for the America's Army game and members we will be using xfire for voice chat. Heres the question:

Is there any way to use PHP to see the status of xfire members to put on the "Who's Online" page?

I'm am still very new to PHP and I'm wondering if this is possible.
Thanks

Last edited by fbelzile; 01-03-2006 at 11:14 PM.. Reason: Solved
fbelzile is offline   Reply With Quote
Old 01-03-2006, 02:41 PM   PM User | #2
fbelzile
New Coder

 
Join Date: Jun 2005
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
fbelzile is an unknown quantity at this point
I just found out that this will be impossible.

I need to parse every profile page. I know it will take a while, but how would I do this?

Heres my profile page:

http://profile.xfire.com/fbelzile
fbelzile is offline   Reply With Quote
Old 01-03-2006, 03:47 PM   PM User | #3
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
To get a single users status i would do this:
PHP Code:
<?php

// set the username of the person
$user 'fbelzile' /*'manikowski'*/;

// get the profile page from the xfire server
// you have to have allow-url-fopen enabled
// info: http://uk2.php.net/ref.filesystem#ini.allow-url-fopen
$page file_get_contents('http://www.xfire.com/xf/modules.php?name=XFire&file=profile&uname=' $user);

// match the "User is: online/offline"
preg_match('#\<strong\>User is\:\</strong\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>#isU'
                      
,$page,$match);

// if everything worked,
// $match[1] is now online or offline
echo $user ' is ' $match[1];

?>
If you want multiple users, and they will all be in your (or someone else's) friends list, you could grab them all at the same time and sort using pre_match_all. It would be faster than getting them individually because you'd only have to request one page instead of many pages.
schleppel is offline   Reply With Quote
Old 01-03-2006, 05:46 PM   PM User | #4
fbelzile
New Coder

 
Join Date: Jun 2005
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
fbelzile is an unknown quantity at this point
Awesome!
Thats what I'm talkin about

OK, sorry but I'm very new to PHP still and I'm wondering how to get multiple users from that one page (my friend(s) on the same page)...

Sorry if Im asking for a lot, but code will help.


Thank-you so much!!
fbelzile is offline   Reply With Quote
Old 01-03-2006, 06:49 PM   PM User | #5
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
This outputs a HTML list of users and status from the page, the person's profile first, and all the people from the friends list:
PHP Code:
<?php

// set the username of the person
$user 'fbelzile';

// get the profile page from the xfire server
// you have to have allow-url-fopen enabled
// info: http://uk2.php.net/ref.filesystem#ini.allow-url-fopen
if(($page file_get_contents('http://www.xfire.com/xf/modules.php?name=XFire&file=profile&uname=' $user)) === false)
    {
        exit(
'Could not load file.');
    }

// match the "User is: online/offline"
preg_match('#\<strong\>User is\:\</strong\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>#isU',$page,$match);

// match you friends status's
preg_match_all('#\<li\>\s+\<span class\="status"\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>.+\</span\>.+\<a href\="[^"]+"\>([^\<]+)\</a\>#isU',$page,$matches);

// echo profile owners status
echo "<ul>\n\t<li>" $user ' is ' $match[1] . '</li>';
// loop through and echo friends status's
foreach($matches[2] as $key => $value)
    {
        
// $value is the username and $matches[1][$key] is the status
        
echo "\n\t<li>" $value ' is ' $matches[1][$key] . '</li>';
    }
echo 
"\n</ul>";

?>
schleppel is offline   Reply With Quote
Old 01-03-2006, 09:34 PM   PM User | #6
fbelzile
New Coder

 
Join Date: Jun 2005
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
fbelzile is an unknown quantity at this point
Nice!!
Now, if I wanted to only display the users online, how would I do that?
(Last question, I swear! lol)

I got this, but its only displaying the name Tyler...

PHP Code:
<?php

$user 
'fbelzile';

if((
$page file_get_contents('http://www.xfire.com/xf/modules.php?name=XFire&file=profile&uname=' $user)) === false)
    {
        exit(
'Could not load file.');
    }

preg_match('#\<strong\>User is\:\</strong\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>#isU',$page,$match);

preg_match_all('#\<li\>\s+\<span class\="status"\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>.+\</span\>.+\<a href\="[^"]+"\>([^\<]+)\</a\>#isU',$page,$matches);

foreach(
$matches[2] as $key => $value)
{
       if(
$matches[2][$key] = 'online')
  
       {
             echo 
$value;
       }
       
       if(
$matches[2][$key] = 'offline')
       
       {
            echo 
"";
       }
}

?>
Laugh at me if you want! Im a real PHP newbie

Thanks again.
fbelzile is offline   Reply With Quote
Old 01-03-2006, 09:54 PM   PM User | #7
Prikid
New Coder

 
Join Date: Dec 2005
Posts: 36
Thanks: 0
Thanked 0 Times in 0 Posts
Prikid is an unknown quantity at this point
you'd need to setup a loop before calling this script. Not such a flexible example (would be more flexible if you were pulling information from database)
PHP Code:
<?
$users 
= array("user1","user2","user3","user4");

foreach (
$users as $key => $user)
{

... 
the script above 
}
?>
Prikid is offline   Reply With Quote
Old 01-03-2006, 10:54 PM   PM User | #8
schleppel
Regular Coder

 
Join Date: Oct 2004
Posts: 330
Thanks: 0
Thanked 13 Times in 13 Posts
schleppel is an unknown quantity at this point
This should work, hopefully:
PHP Code:
<?php

// set the username of the person
$user 'fbelzile';

// get the profile page from the xfire server
// you have to have allow-url-fopen enabled
// info: http://uk2.php.net/ref.filesystem#ini.allow-url-fopen
if(($page file_get_contents('http://www.xfire.com/xf/modules.php?name=XFire&file=friends&uname=' $user)) === false)
    {
        exit(
'Could not load file.');
    }

// match the "User is: online/offline" 
preg_match('#\<strong\>User is\:\</strong\>.+\<span class\="[^"]+"\>\<b\>([^\<]+)\</b\>\</span\>#isU',$page,$match);
  
// match you friends status's
preg_match_all('#\<td width\="22%"\>\s+\<a href\="modules\.php\?[^"]+"\>([^\<]+)\</a\>\s+\</td\>\s+\<td width\="13%"\>\s+\<span class\="[^"]+"\>(online|offline)\</span\>#isU',$page,$matches);
     
// start the HTML list
echo "<ul>\n\t";

// check if the profile's owner is online
if($match[1] == 'online')
    {
        echo 
'<li>' $user '</li>';
    }

// loop through the matched friends
foreach($matches[1] as $key => $value)
{       
       
// check if they're online.
       
if($matches[2][$key] == 'online')
  
       {       
             
// echo name
             
echo "\n\t<li>" $value '</li>';
       }
}

// end list
echo "\n</ul>";

?>
Edit: I updated the URL to the friends page.
Edit2: copied in the script again, i think i messed it up the first time.

Last edited by schleppel; 01-03-2006 at 10:59 PM..
schleppel is offline   Reply With Quote
Old 01-03-2006, 11:13 PM   PM User | #9
fbelzile
New Coder

 
Join Date: Jun 2005
Posts: 40
Thanks: 2
Thanked 0 Times in 0 Posts
fbelzile is an unknown quantity at this point
THANK-YOU!!

You helped me a lot in making my site!
Man, I love this forum

I have always got an answer for every question I had.

Thanks again schleppel (and Prikid, for the answer I never got to try)
Have a good day
fbelzile is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:38 PM.


Advertisement
Log in to turn off these ads.