Announcement

Collapse
No announcement yet.

Who's Online For A site

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Who's Online For A site

    I am making a PHP Who's Online that can be used on a main site just by calling it via SSI. The problem is it only displays one person online.

    PHP Code:
    <?

    $ip 
    getenv("REMOTE_ADDR");
    $laps 300;
    $data "data.txt";
    $ctime time();
    $expire $ctime $laps;

    function 
    filecount($filename) {
      if (
    file_exists($filename)) {
        
    $tmp file($filename);
        
    $cnt count($tmp);
        
    $cnt++;
        return(
    $cnt);
      } else {
        return(
    "Sorry, file does not exist");
      }
    }

    if(
    file_exists($data))
    {
    $fp fopen("$data","r");
    while (!(
    feof($fp)))
    {
    $buffer fgets($fp4096);
    list(
    $ip_tmp$expire_tmp) = explode("|",$buffer);
    if((
    $ip_tmp != $ip) && ($expire_tmp $ctime))
    {
    $foo[]="$ip_tmp|$expire_tmp";
    }
    }
    fclose($fp);
    }

    $fp fopen("$data","w");
    if (
    flock($fp2))
    {
    if(
    is_array($foo))
    {
    while (list(
    $key$val) = each($foo))
     {
    fputs($fp,$val);
    }
    }

    fputs($fp,"$ip|$expire\n");
    }
    flock($fp3);
    fclose($fp);

    $userz filecount($data);

    Print(
    "There is $userz online");

    ?>
    Scott MacVicar

    My Blog | Twitter
widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
Working...
X