#native_company# #native_desc#

Php Private Chat

By kakchan
on March 9, 2004

Version: 0.01

Type: Sample Code (HOWTO)

Category: Databases

License: GNU General Public License

Description: Hello this script is very usefull when you need unlimited chat on your web site, is very easy to install, create 4 file and put the follow code into them…
this script is fully open source you can modify it as you needed but notify me before.
remember to change db settings with your own settings

Database Dump:

# Table structure for table `chat_private`

CREATE TABLE `chat_private` (
`chat_date` int(10) default NULL,
`chat_psw` varchar(20) NOT NULL default ”,
`chat_msg` text NOT NULL

// File index.php 

<body bgcolor="#000000" text="#FFFFFF"> 
<div align="center"> 
    <form name="form1" method="post" action="chat_read.php"> 
    Password: <input name="password" type="text" id="password" maxlength=20> 
    Nickname: <input name="nickname" type="text" id="nickname" maxlength=20> 
    <input name="Entra" type="submit" id="Entra" value="Entra"> 

// File chatlib.php 
// Db config 
$hostname = ""; 
$user = ""; 
$password = ""; 
<script language='JavaScript'> 
function focus() { 
function aggiorna() { 
<body bgcolor='#000000' text='#FFFFFF' vlink='#0000FF' onload='javascript:focus();'> 
<form name='mesform' action='chatlib.php' method='POST'> 
    <input type='hidden' name='password' value='<?=$password?>'> 
    <input type='text' size='20' name='message'> 
        <input type='submit' value='Send'> 
    <input type='button' name='Aggiorna' value='Aggiorna' onclick='javascript:aggiorna();'> 

if (empty($message)) { 

$message = htmlspecialchars($message); 
$message = mysql_escape_string($message); 
$message = strip_tags($message); 

if (!isset($msg)) { 
$msg = "$nickname : $message"; } 

function php_private_chat($password,$msg) { 
$time = time(); 
mysql_db_query($db,"insert into chat_private (chat_date,chat_psw,chat_msg) values ($time,'$password','$msg')"); 
$time = $time - 86400; 
mysql_db_query($db,"delete from chat_private where chat_date <= $time"); 

$msg = stripslashes($msg); 
$db = mysql_connect($hostname, $user, $password); 

// File chat_text.php 
echo "<meta http-equiv='Refresh' content='10'>"; 
// Db config 
$hostname = ""; 
$user = ""; 
$password = ""; 
<body bgcolor='#000000'> 
$db = mysql_connect($hostname, $user, $password); 
$query = mysql_db_query($db,"select chat_msg from chat_private where chat_psw = '$password' and chat_date >= ($time-600) order by chat_date desc limit 0,20"); 
$num = mysql_num_rows($query); 
for ($i=0;$i<$num;$i++) { 
$array = mysql_fetch_array($query); 
echo $array[chat_msg]; 

// File chat_read.php 
<FRAMESET frameborder='no' border='0' ROWS='*,60'> 
<FRAME name='chatroom' SRC='chat_text.php?password=<? echo strtolower($password); ?>&time=<? echo time();?>'> 
<FRAME name='sendbar' SRC='chatlib.php?password=<? echo strtolower($password);?>'>