Chatroom with Users who logged in the website

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
asterinex
Forum Commoner
Posts: 52
Joined: Thu Nov 25, 2004 7:01 am
Location: Belgium

Chatroom with Users who logged in the website

Post 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
[]InTeR[]
Forum Regular
Posts: 416
Joined: Thu Apr 24, 2003 6:51 am
Location: The Netherlands

Post 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>
Post Reply