<?php
// Config : [ You can change these options ] $refresh = 6 ; // Page refresh time in seconds $max = 20 ; // Max. saved messages $remain = 400 ; // Messages remaining time in seconds $file = "msg.txt" ; // Message storing file
/*
You may need to make an empty file (use notepad) and name it "msg.txt"
($file), and send it to your server. Then CHMOD this file to 777 - e.g :
ftp> SITE CHMOD 777 msg.txt
*/
// End of config //
$user = $HTTP_SERVER_VARS['REMOTE_ADDR'] ; $f = file($file) ; $users = array($user) ; header ("Content-Type: text/html; charset=utf-8") ; $fp = fopen($file, "w") ;
if (!$fp) { die ('Can not write to file .') ; }
for ($i=0; isset($f[$i])||$i==0; $i++)
{
$e=explode('||', $f[$i]) ;
if ($e[2]=="rn" && !in_array($e[0], $users) && ( time() - $e[1] < $refresh*2 ) ) $users[]=$e[0] ;
if ($i==0) { fputs($fp, $user."||".time()."||rn") ;
if ( isset($HTTP_POST_VARS['msg']) ) fputs ($fp, $user."||".time()."||".str_replace("||", "", str_replace("n", "", htmlspecialchars(stripslashes($HTTP_POST_VARS['msg']))))."rn") ; }
if ( ($e[0]!=$user && $e[2]=="rn") || ( $i<$max && ($e[1]+$remain)>time() && $e[2]!="rn") ) fputs($fp, $f[$i]) ;
} fclose($fp) ;
if (isset($HTTP_GET_VARS['f1']))
{
$f2 = file($file) ;
echo("<html><head><title></title><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head>") ;
echo("<body text=#0000cc><meta http-equiv='refresh' content='{$refresh}; url={$HTTP_SERVER_VARS['REQUEST_URI']}'>") ;
echo("<font color=#e22200>Online Users: ") ;
foreach($users as $u) echo "<font color=#ee0099>".$u."</font> - " ;
echo "</font><hr>" ;
for($i=0; isset($f2[$i]) && $i<$max; $i++) {
$e=explode("||", $f2[$i]) ;
if ($e[2]!="rn") echo "<font color=green>{$e[0]}</font> <font color=red>:</font> {$e[2]}<br>rn" ;
}
die("</body></html>") ;
}
else
{
die("
<html><head><title>Chat</title><meta http-equiv='Content-Type' content='text/html; charset=utf-8'>
<script><!--
function msg(){ document.m.msg.focus(); } // --></script>
</head>
<body align='center' onLoad='msg()'> <center>
<iframe src='?f1=1' width='95%' height='85%'></iframe><br>
<table width='95%'><tr><td align='center' width='100%'>
<form action='' method='post' name='m'>
Message : <input name='msg' size=60> <input type='submit' name='send' value='Send'>
<br />
</form>
</td></tr></table>
</body></html>
") ;
} ?>
|
|