Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Jun 2005
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts

    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

  • #2
    New Coder
    Join Date
    Jun 2005
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #3
    Regular Coder
    Join Date
    Oct 2004
    Posts
    356
    Thanks
    0
    Thanked 16 Times in 16 Posts
    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.

  • #4
    New Coder
    Join Date
    Jun 2005
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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!!

  • #5
    Regular Coder
    Join Date
    Oct 2004
    Posts
    356
    Thanks
    0
    Thanked 16 Times in 16 Posts
    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>";

    ?>

  • #6
    New Coder
    Join Date
    Jun 2005
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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.

  • #7
    New Coder
    Join Date
    Dec 2005
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 
    }
    ?>

  • #8
    Regular Coder
    Join Date
    Oct 2004
    Posts
    356
    Thanks
    0
    Thanked 16 Times in 16 Posts
    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.

  • #9
    New Coder
    Join Date
    Jun 2005
    Posts
    42
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •