close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Show online users

Thread began 6/03/2010 10:59 pm by Miguel | Last modified 6/04/2010 4:02 pm by Miguel | 2250 views | 6 replies

Miguel

Originally Said By: Jason Byrnes
  that system takes care of logging out via the log in button, and logging them out if they have a page from your site open, but are inactive. but it does not take care of the big problem when a user simply closes the browser, or goes to another site without logging out first.  



Yep very true this is what i did

STEP 1

on my user or login table i added these at the end

`conected_usr` char(1) COLLATE latin1_general_cs DEFAULT 'N',
`tm_usr` datetime DEFAULT '0000-00-00 00:00:00',

both of them i set them to NULL

STEP 2
Open up the login page:
on the login page instead of making the log table wich i have for other propose (i made my logs kind of addt style so i didnt want to use that one)

i did an update single record with data assist filtered by the User session ID and binded "Y" value to my conected_usr field and the exact date for tm_usr, this to our users table or login table
Save the login page.

STEP 3
Open up your logout.php page or how ever you name it and added with data assist an update again similiar to the login page but with the conected_usr binded value to "N" and also update the tm_usr field for the exact datetime.

STEP 4

Create a new page called whoischeck.php or what ever name you like
i first used security assist on a comon place with the show if region and modify it to this script also add your conecction on top of all

php:
<?php require_once('../Connections/conectpage.php'); ?>
<?php 
require_once( "../WA_SecurityAssist/Helper_PHP.php" ); ?>
<?php
////// To update session status for user table to get who is online ////////
if(WA_Auth_RulePasses("Logged in to users")){ // Begin Show Region 
$tm=date("Y-m-d H:i:s");
$xses=$_SESSION['UsID'];
$q=mysql_query("update usertb set conected='Y',tm='$tm' where UserID='$xses'");
//echo "<center><font face='Verdana' size='2' ><br>Welcome $xses Click <a href=logout.php>here to logout</a> &nbsp; | &nbsp; <a href=change-password.php>Change Password</a>| &nbsp; <a href=update-profile.php>Update Profile</a><br></center></font>";
echo $tm;
echo 
mysql_error();}
else{
//echo "<center><font face='Verdana' size='2' ><a href=login.php>Already a member, please Login</a> </center></font>";

}

///// ////////////// End of updating login status for who is online ///////

// Find out who is online ///////// 
$gap=10// change this to change the time in minutes, This is the time for which active users are collected. 
$tm=date ("Y-m-d H:i:s"mktime (date("H"),date("i")-$gap,date("s"),date("m"),date("d"),date("Y")));
//// Let us update the table and set the status to OFF 
////for the users who have not interacted with 
////pages in last 10 minutes ( set by $gap variable above ) ///

$ut=mysql_query("update usertb set conected='N' where tm < '$tm'");
echo 
mysql_error();
/// Now let us collect the userids from table who are online ////////
$qt=mysql_query("select UsID from usertb where tm > '$tm' and conected='Y'");
echo 
mysql_error();

while(
$nt=mysql_fetch_array($qt)){
//echo "$nt[UsID],";
}

?>


STEP 5


This last file i include it to the sites footer so it loads on every page and also i set a cronjob in order to check every hour if the user table has activity or not, but havent test it yet, the cronjob on cpanel host is something like this

php -q /home/accountname/public_html/crons/whoischeck.php

STEP 6

Now at my administration part i created a file to show me users conected or not conected, i also built a little ticket thing wich allows me to msg quickly users and they will get an icon to check the site msg like a small chat, it also usefull if your building your own forum or message boards.


Hope this helps
Sades

Pd. i have still not tested on a live server yet if any one use this please let us know also if you modify it i just grabbed a tutorial and took the parts mostly for the cronjob to be applyed

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...