Page 1 of 1

chat kick

Posted: Wed Apr 13, 2005 4:46 pm
by s.dot
I have developed a pretty nice PHP/Javascript chat server that works pretty good.

I'm finishing it up, by programming some administration functions.

I'm stuck on the kicking part.

I have a form that sets their status in the database to kicked or '1'

then when my hidden frame reloads itself to grab new messages (once per second) it checks to see if the users status is set to kicked... and if it is I want it to redirect them to a page named chatkick.php.

I can't use php header location because text has already been sent to the page. So I need to use javascript.

I tried this

Code: Select all

$sarray = mysql_fetch_array(mysql_query(&quote;SELECT status FROM chatusers WHERE username = '&quote;.$_COOKIEї'username'].&quote;'&quote;));
if($sarray&#1111;'status'] == &quote;1&quote;){ ?><script language=&quote;javascript&quote;>document.location.href = 'http://www.showmypro.com/chatkick.php'; </script><? }
however, if this does work, it will only reload the current frame. So I tried parent.location = ''; and that didn't work.

What command do I need to use?

Posted: Wed Apr 13, 2005 7:23 pm
by John Cartwright
First of all, I would not rely on cookies in the first place. Cookies can easily be disabled in any browser. In it's place use a table to store their session_id();

Code: Select all

echo '<html>
      <head>
		<title></title>
	 </head>';

$result = mysql_query("SELECT * FROM `active_users` WHERE `session_id` = '".session_id()."' LIMIT 1") or die(mysql_error());

if (mysql_num_rows($result) > 0)
{
	$row = mysql_fetch_assoc($result);
     
	$body = ($row['kick'] == 1 ' onload="setTimeout(\'window.parent.location=\'kickchat.php\',1)"' : '');
}
else
{
	$result = mysql_query ("INSERT INTO `active_users` SET `session_id` = '".session_id()."'");
}

	echo '<body'.$body.'>';
	
	//rest of your page goes here
	//....
	//....
You also might want to checking for expired sessions, or if they have been inactive for a certain period of time, delete their row in `active_users` and force a login.

Posted: Wed Apr 13, 2005 9:49 pm
by s.dot
I have already done the deleting row in active users. And I got the kick to work by using a javascript alert, then redirecting to the kick page.

The chat works awesome now :-D.

How do I check for expired sessions? I have always used cookies.

Posted: Thu Apr 14, 2005 9:53 am
by John Cartwright
on the users row, have a timestamp of the time they last accessed the page.
and then..

Code: Select all

if (($row['timestamp']+300) > time()) //5 minutes 
//delete their row in db