Jump to content

Making “Who is online” without SQL


maxirb

Recommended Posts

Hi All

 

My first post here and also request for help from you experts. I am new to PHP and this question is perhaps very basic to most of you. I need to make a page to monitor “who is online” of another page. Let’s say one user log in on A.php, the moderator on Mod.php can see him/her, also the mod.php can see when he/she logged out. Can this be done with php coding and without creating data in SQL? Thank you all.

 

Max

It depends entirely on your spec however you should checkout fopen() fwrite(), etc within the php manual php.net to learn how to read and write to files. The fist thing you will need is to have a file that is included within all your php pages i.e. application.inc.php. Here you can add you function to write the data to file i.e.

 

function write_user_data() {
  $fp = fopen();
  // etc.......
}

I would say use sessions to hold the name of the file written to for each user otherwise you will keep opening and writing to new files on each page request i.e.

 

<?php
// the user does not have a log file - set one
if(!strlen($_SESSION['filename'])) {
  $_SESSION['filename'] = time().".txt";
}

function write_user_data() {
  $fp = fopen("whosonline/".$_SESSION['filename']
  // etc.......
}

write_user_data();
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.