chat.php
<?php
/**********************************
* Copyright (C) DUzun.ME 2007. *
* All rights reserved. *
**********************************/
session_start();
$chat=&$_REQUEST['chat'];
if(!$chat)
{
if(!empty($_REQUEST['person'])) $_SESSION['person']=trim($_REQUEST['person']);
$person=&$_SESSION['person'];
?>
<form action="" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<b>
<?php if(!isset($person)){?>
Nume:
<input class=sb type="text" name="person" maxlength="80" value="<? echo $person; ?>" style="width:120px" />
<?php }
else
{
print ' < '.$person.' > ';?>
<input type="hidden" name="person" value="<? echo $person; ?>"/>
<?php } ?>
</b> </td>
<td> </td>
</tr>
<tr height="480px">
<td><iframe name="messages" src="<?php print $PHP_SELF.'?chat=messages'; ?>" marginwidth="0" marginheight="0" scrolling="auto" allowtransparency="yes" frameborder="1" width="100%" height="100%" noresize title="Maxi <?php echo $msg_count;?> mesaje"/>
</iframe></td>
<td width="20%">
<iframe src="<?php echo $PHP_SELF.'?chat=online';?>" name="online" width="100%" height="100%" frameborder="0" allowtransparency="allowtransparency" align="left" scrolling="auto"></iframe></td>
</tr>
<tr>
<td colspan="2">
<b>Mesaj:</b>
<input class='sb' style="background-color:#ffddff; width:100%; height:60px; vertical-align:top" name="message" type="text" maxlength="256"/> </td>
</tr>
<tr>
<td><input name="submit" type="submit" class=sb2 value="Post" /></td>
<td>
</td>
</tr>
<tr>
<td>
<a href="javascript://(void)" onclick="document.getElementById('code').style.display = block;">Aratã codul PHP al acestui chat!</a> </td>
<td>
</td>
</tr>
</table>
</form>
<iframe src="<?php echo $PHP_SELF.'?chat=updater';?>" style="display:none" name="updater">
<?php
include "option.php";
$_SESSION['chat_msg_file'] = $msg_file;
$_SESSION['chat_online'] = $online_file;
$_SESSION['chat_update_time'] = $update_time;
$fl = file($msg_file);
$count_fl = count($fl);
$msg = stripslashes(trim($_POST['message']));
if (($msg != "") && ($person != "")){
if ($count_fl >= $msg_count){
$fw = fopen($msg_file, "w");
for($i=1;$i<$msg_count;$i ) fwrite($fw, trim($fl[$i])."\r\n");
}
$time = date("H:i, d-m-y",time() 3600);
$fp = fopen($msg_file, "a ");
$fw = fwrite($fp, "<span class=d2><b style=\"color:#3d3232\"> ".$person." :</b> <I style=\"color:#5f2bde\">".$time."</I><br>".$msg."<hr size=-2 color=\"#3d3232\"></span>\r\n");
fclose($fp);
$_SESSION['chat_lastupdate']=filemtime($_SESSION['chat_msg_file']);
echo '<script>window.parent.messages.document.location.reload();</script>';
}
}else switch($chat){
case('messages'):
echo '<head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2" /></head>';
?>
<script language="javascript">
function getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n;
if(!o)o=document;
if(o.getElementById) el=o.getElementById(id); else if(o.layers) c=o.layers; else if(o.all) el=o.all[id];
if(el) return el;
if(o.id==id || o.name==id) return o;
if(o.childNodes) c=o.childNodes;
if(c) for(n=0; n<c.length; n ) { el=getObjectByID(id,c[n]); if(el) return el; }
f=o.forms;
if(f) for(n=0; n<f.length; n ) {
els=f[n].elements;
for(m=0; m<els.length; m ){ el=getObjectByID(id,els[n]); if(el) return el; }
}
return null;
}
</script>
<?php
$options_file = "option.php";
include $options_file;
$fmsg = file($msg_file);
$count_msg = count($fmsg);
for($i = 0; $i < $count_msg; $i ) echo $fmsg[$i];
echo '<span id="end"><script language="javascript">getObjectByID("end").scrollIntoView(true)</script></span>';
$_SESSION['chat_lastupdate']=filemtime($_SESSION['chat_msg_file']);
break;
case('updater'):
echo '<html><head><meta HTTP-EQUIV="Refresh" CONTENT="'.$_SESSION['chat_update_time'].'"><meta name="pragma" content="no-cache"></head>';
if( $_SESSION['chat_msg_file'] && (filemtime($_SESSION['chat_msg_file'])==$_SESSION['chat_lastupdate']) ){ return false;}
else
{ echo '<script>window.parent.messages.document.location.reload();</script>';
$_SESSION['chat_lastupdate']=filemtime($_SESSION['chat_msg_file']);
}
echo '</html>';
break;
case('online'):
echo '<html><head><meta HTTP-EQUIV="Refresh" CONTENT="'.($_SESSION['chat_update_time']).'"><meta name="pragma" content="no-cache"></head>';
echo '<div align=center><u>online acum</u></div><br>';
$t=time()-$_SESSION['chat_update_time']-1;
$added=false; $prsn=$_SESSION['person'];
$r=array();
if(is_file($fl=$_SESSION['chat_online'])){
$ar=file($fl); $cnt=count($ar);
for($i=0;$i<$cnt;$i =2){
if(!(($ar[$i]=trim($ar[$i]))&&($ar[$i 1]=trim($ar[$i 1])))) continue;
if(($ar[$i 1]==$prsn) && !$added){ $ar[$i]=time(); $added=true; }
if(($ar[$i]>$t) && ($ar[$i 1])){ $r[]=$ar[$i];$r[]=$ar[$i 1];}
}
}
if(!$added){ $r[]=time(); $r[]=$prsn; }
$cnt=count($r);
for($i=1;$i<$cnt;$i =2){
echo $r[$i].'<br>';
}
if(!$f=fopen($fl,'w')) return;
foreach($r as $v){ fwrite($f,$v."\n"); }
fclose($f);
break;
} ?>
options.php
<?php
$msg_file = "mesage.htm";
$online_file = "online.txt";
$log_file = "log.txt";
$update_time = 5;
$msg_count = 25;
if (!file_exists($msg_file)) { $fo = fopen($msg_file, "w"); fclose($fo); }
?>