Page 1 of 1

Chatroom with Users who logged in the website

Posted: Fri Nov 26, 2004 2:37 am
by asterinex
I have a website where people can login . The site contains a forum,..... . Now I want integrate a chatroom. Does anyone know free chatroom code that is easy enough to integrate with my database of USERS ?


Or any other ideas?


Thanks

Posted: Wed Dec 01, 2004 9:11 am
by []InTeR[]
That room code is can be realy simple.

Make a frameset, with 2 frames (top,bottom).
top.php

Code: Select all

<?php

  mysql_connect('host','user','pass');
  mysql_select_db('yours');
  $last_id = 0;

  while(TRUE){
 
    $query = "SELECT
                      `user`.`username`,
                      `chat`.`line`,
                      `chat`.`id`
                    FROM `chat`
                    LEFT JOIN `user` ON `user`.`id` = `chat`.`user_id`
                    WHERE `chat`.`time` less then 5 min."
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result)){
      echo '<b>'.$row['user'].'</b>: '.$row['line'].'<br>';
      $last_id = $row['id'];
    }
    sleep(1);
  } 
?>
And a bottom.php

Code: Select all

<?php
  if(isset($_REQUEST['line']))
  {
    mysql_connect('host','user','pass');
    mysql_select_db('yours');
    $query = "INSERT INTO `chat` (`user_id`,`line`,`time`) VALUES ('".$SESSION['user_id']."','".$_REQUEST['line']."',NOW())";
    mysql_query($query);
  }
?>
<form>
  <input type="text" name="line">
</form>