SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2008
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to display text if session isset?

    I want to display "ONLINE" when a user is logged into their account so other users will know their online.

    I'm thinking about doing it using the $_SESSION variable and if it's isset the program will UPDATE a 'Y' in their ONLINE field of their database table that way i could display 'ONLINE' based on that field being a 'Y' or a 'N' will this work and if i do it that way will i be able to to UPDATE their ONLINE field with a 'N' when the session ends or by my logout.php code below...

    <?php
    session_start();

    include 'config.php';
    include 'opendb.php';
    if(true == session_unregister('member_ID')) :
    $query = "UPDATE table(online) VALUES('N');
    mysql_query($query) or die('Error, insert query failed');
    header('Location: index.php?msg=logout_complete');
    else :
    $query = "UPDATE table(online) VALUES('N');
    mysql_query($query) or die('Error, insert query failed');
    unset($_SESSION['member_ID']);
    sleep(3);
    header('Location: index.php?msg=logout_complete');
    endif;
    ?>

    will this principle work or is there another way? i only want to use the session variable for this.

    Cheers in advance

  2. #2
    SitePoint Enthusiast jcarouth's Avatar
    Join Date
    Sep 2006
    Location
    College Station, TX
    Posts
    48
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That is essentially how most "who's online" features work. You might consider changing your Y or N idea into a last activity timestamp. With the last activity data you could then set a threshold of arbitrary duration that signifies a user "offline" based on their inactivity. Otherwise, you'll need some way to attach session identifiers to the users to check for the close of a session, and offline users will be considered online by the system.


Bookmarks

Posting Permissions

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