Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthoreplawless
    • CommentTimeAug 28th 2006
     permalink
    I'm coding an AJAX chatroom, and I'm storing a list of users online in an xml file. When someone logs on it adds them without any problem, but I'm having a hard time trying to figure out how to remove them from the list when they log out. My code is below, and I am extremely new to XML so please don't laugh at me. Does anyone know how I can make php open the file, delete any nodes where the ip attribute matches the ip of the user, and save the file?

    $users = new DomDocument();
    $users->load("../data/users.xml");

    $xp = new domXPath($users);
    $query = "/user[@ip=".$ip."]";
    $results = $xp->query($query);

    $count = count($results);
    for ($j = 0; $j < $count; $j++) {
    $users->documentElement->removeChild($results->item($j));
    }

    $users->save("../data/users.xml");
    • CommentAuthoreplawless
    • CommentTimeAug 29th 2006
     permalink
    Never mind; SimpleXML to the rescue.

    //update users list
    $userfile = new DomDocument();
    $userfile->load("../data/users.xml");

    $suser = simplexml_load_file("../data/users.xml");
    $count = 0;
    foreach($suser->user as $user) {
    if ($user['ip'] == $ip) {
    $userfile->documentElement->removeChild($userfile->documentElement->childNodes->item($count));
    $count--;
    }
    $count++;
    }

    $userfile->save("../data/users.xml");
    • CommentAuthorbriantan
    • CommentTimeOct 4th 2010 edited
     permalink
    I have been banned cause I'm an idiot
    There will always be the desire to keep expenses down or to cut corners, but one must take the complete picture into account. On the Internet the first impression a visitor (potential customer) gets is everything. [url=http://lionheart.net/]tampa seo[/url]
Add your comments
    Username Password
  • Format comments as (Help)