Results 1 to 5 of 5

Thread: Building a Forum.....

  1. #1
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Building a Forum.....

    Hi to all,
    I'm building a forum and I want to be able to see who's online! If anyone knows anything I'd appreciated!!

    Thanks in advance!!

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Sessions. Not just PHP sessions, but stored in a database with matching info (good for security too, to compare).
    Then display all of the names of people who have active sessions.
    You could also use time in either deleting sessions that have been inactive for some amount of time, such as 15 minutes.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2006
    Posts
    70
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I found another way to see who's online! But how can I store sessions in db? Just for the knowledge and why not including it in my forum if it's better! Also, I want to have a permission system that would be different for each group in each forum! (Note that the forums are dynamically set by the admin) Any help would be appreciated!!

    Thanks for answering!

  4. #4
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Quote Originally Posted by costas
    But how can I store sessions in db?
    PHP Code:
    <?php
      $GLOBALS
    ['sess_server'] = 'localhost';
      
    $GLOBALS['sess_db'] = 'sessions';
      
    $GLOBALS['sess_username'] = 'user';
      
    $GLOBALS['sess_password'] = 'pass';

      function 
    sess_open() {
        
    $GLOBALS['sess_mysqli'] = mysqli_connect(
          
    $GLOBALS['sess_server'], 
          
    $GLOBALS['sess_username'], 
          
    $GLOBALS['sess_password']
        );
        
    mysqli_select_db($GLOBALS['sess_mysqli'], $GLOBALS['sess_db']);
      }
      
      function 
    sess_close() {
        
    mysqli_close($GLOBALS['sess_mysqli']);
      }
      
      function 
    sess_read($id) {
        
    $result mysqli_query(
          
    $GLOBALS['sess_mysqli'],
          
    sprintf('SELECT data FROM sessiondata WHERE id = \'%s\'',
            
    mysqli_real_escape_string($GLOBALS['sess_mysqli'], $id))
        );
        if (
    $row mysqli_fetch_object($result)) {
          
    $ret $row->data;
          
    mysqli_query(
            
    $GLOBALS['sess_mysqli'], 
            
    sprintf('UPDATE sessiondata SET access=\'%s\' WHERE id=\'%s\'',
              
    date('YmdHis'), 
              
    mysqli_real_escape_string($GLOBALS['sess_mysqli'], $id))
          );
        } else {
          
    $ret '';
        }
        return 
    $ret;
      }
      
      function 
    sess_write($id$data) {
        
    mysqli_query(
          
    $GLOBALS['sess_mysqli'],
          
    sprintf('UPDATE sessiondata SET data=\'%s\', access=\'%s\' WHERE id=\'%s\'',
            
    mysqli_real_escape_string($GLOBALS['sess_mysqli'], $data), 
            
    date('YmdHis'), 
            
    mysqli_real_escape_string($GLOBALS['sess_mysqli'], $id))
        );
        if (
    mysqli_affected_rows($GLOBALS['sess_mysqli']) < 1) {
          
    mysqli_query(
            
    $GLOBALS['sess_mysqli'],
            
    sprintf('INSERT INTO sessiondata (data, access, id) VALUES (\'%s\', \'%s\', \'%s\')',
              
    mysqli_real_escape_string($GLOBALS['sess_mysqli'], $data), 
              
    date('YmdHis'), 
              
    mysqli_real_escape_string($GLOBALS['sess_mysqli'], $id))
          );
        }
        return 
    true;
      }
      
      function 
    sess_destroy($id) {
        
    mysqli_query(
          
    $GLOBALS['sess_mysqli'], 
          
    sprintf('DELETE FROM sessiondata WHERE id=\'%s\''
            
    mysqli_real_escape_string($GLOBALS['sess_mysqli'], $id))
        );
        return 
    true;
      }
      
      function 
    sess_gc($timeout) {
        
    $timestamp date('YmdHis'time() - $timeout);
        
    mysqli_query(
          
    $GLOBALS['sess_mysqli'],
          
    sprintf('DELETE FROM sessiondata WHERE access < \'%s\'',
            
    $timestamp)
        );
      }
      
      
    session_set_save_handler(
        
    'sess_open''sess_close''sess_read'
        
    'sess_write''sess_destroy''sess_gc');
    ?>
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  5. #5
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    I don't know why you're using $GLOBALS... just use $_SESSION, if that is indeed your goal...
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

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
  •