maxirb Posted August 5, 2009 Share Posted August 5, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/168963-making-%E2%80%9Cwho-is-online%E2%80%9D-without-sql/ Share on other sites More sharing options...
JonnoTheDev Posted August 5, 2009 Share Posted August 5, 2009 Of course, however a database server is the most efficient method. Your other option is to create a logging function that will write information to file. Quote Link to comment https://forums.phpfreaks.com/topic/168963-making-%E2%80%9Cwho-is-online%E2%80%9D-without-sql/#findComment-891440 Share on other sites More sharing options...
maxirb Posted August 5, 2009 Author Share Posted August 5, 2009 Hi, wow that was quick..any chance to show me how the coding would looks like,..in general.. Quote Link to comment https://forums.phpfreaks.com/topic/168963-making-%E2%80%9Cwho-is-online%E2%80%9D-without-sql/#findComment-891444 Share on other sites More sharing options...
Mark Baker Posted August 5, 2009 Share Posted August 5, 2009 A rather naughty alternative would be to read all of the session files in the tmp directory, assuming every user had a session Quote Link to comment https://forums.phpfreaks.com/topic/168963-making-%E2%80%9Cwho-is-online%E2%80%9D-without-sql/#findComment-891450 Share on other sites More sharing options...
JonnoTheDev Posted August 5, 2009 Share Posted August 5, 2009 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(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/168963-making-%E2%80%9Cwho-is-online%E2%80%9D-without-sql/#findComment-891451 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.