Zend - The PHP Company




Chat

Add Code


Simple Simple Chat  

Type: application
Added by: samdeath
Entered: 15/08/2006
Last modified: 09/12/2005
Rating: - (fewer than 3 votes)
Views: 3791
******************************* *** Simple Simple Chat *** *** v 1.0 *** *** www.phpclub.site.ir *** ******************************* // Warning : This chat exposes chatters IP addresses


<?php

// Config : [ You can change these options ]
$refresh // 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*) ) $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>
    "
) ;
}
?>


Usage Example


See the example


Rate This Script





Search



This Category All Categories