i have this php code below:
i want to display users that are online . if they are not active the next 20 min then there name will not be displayed and there status will be turned OFF in th database table tng_users field status

but i also want all session to be cleared when this users status turn OFF because that means he wont be online or active and i want him clear all the sessions when his status turn to OFF.

how do i do that??
thanks!!

?>

$gap=20; // 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 20 minutes ( set by $gap variable above ) ///
require('online_connect.php');
$ut=mysql_query("update tng_users set status='OFF' where tm < '$tm'");
echo mysql_error();
$test = mysql_query("SELECT * FROM tng_users WHERE status='ON'");
$num_rows = mysql_num_rows($test);
if ($num_rows == 0){
echo "sorry,there are no users online!";}
$whoo = mysql_query("SELECT username,country FROM tng_users WHERE status='ON'");
while($username = mysql_fetch_array($whoo)){
echo "$username[username]..$username[country]";

echo "<br/>";}
//}
?>

how about session_unset?

To unset a session simply use the following.

<?php session_start(); //first line of file
//blah...
$_SESSION=array(); //unset session

cant i have a query that will say...

if ($ut){

session_unset();

}

???? SO IF THE $ut is true.($ut=mysql_query("update tng_users set status='OFF' where tm < '$tm'");) to unset session?? but when i refresh the page it unsets it...

you need to be a little more specific.
try:

if($ut = false){
session_unset();
}

you need to specify what you want the if to check against.
e.g:

IF($score > 90){
echo 'excellent!'
}

otherwise it is just stating if $ut exists execute session_unset()
hope this helped :)

try:

if($ut = false){
session_unset();
}

I think you mean: if($ut == false) ?

ah yes sorry wasn't quite paying full attention there.

<?PHP
if($ut == false){session_unset();}
?>

better now. common typo error :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.