Jump to content

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();
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.