0

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/>";}
//}
?>

5
Contributors
6
Replies
7
Views
7 Years
Discussion Span
Last Post by metalix
0

To unset a session simply use the following.

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

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

0

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 :)

0

try:

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

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

Edited by n_e: n/a

0

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

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

better now. common typo error :P

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.