Girovagando su freephp ho trovato questa semplice chat in php, ottima per l'uso che devo farci...c'è solo un problema...Quando due persone sono connesse nella chat, ciò che scrive una persona viene visto dall'altra solo quando quest'ultima scrive qualcosa anche lui. In pratica la chat non si aggiorna automaticamente, ma si aggiorna solo premendo F5 o inviando qualcosa...effettivamente funziona più come una tagboard, che come una chat...il codice è tutto incluso in una sola pagina php:
codice:
<?php header ("Pragma: no-cache"); ?>
<?
//GO TO WHERE IT SAYS 'EDIT THESE VARS', and 'FEATURES'
// DONT EDIT
function tg($action, $nick, $stuffsaid, $personsite){
$talkdatafile = "tc.txt";
//FEATURES
$sfeature = "0";
//site feature, make it 1 to enable
if ($sfeature == "1"){
if ($action == "talk") {
if(strlen($nick) >= 3){
if(strlen($stuffsaid) >= 3){
$t_fp = fopen ($talkdatafile, "a+");
$talkdate = date("H:i d/m/y");
$ip = getenv(REMOTE_ADDR);
$nicktwo = ereg_replace('<', ' ', $nick);
$nickthree = ereg_replace('>', ' ', $nicktwo);
$personsiteone = ereg_replace('<', '', $personsite);
$personsitetwo = ereg_replace('>', '', $personsiteone);
$personsitefinal = ereg_replace(' ', '', $personsitetwo);
$one_stuffsaid = ereg_replace('<', ' ', $stuffsaid);
$two_stuffsaid = ereg_replace('>', ' ', $one_stuffsaid);
$f_stuffsaid = stripslashes("$two_stuffsaid");
$f_nick = stripslashes("$nickthree");
$writedata = $talkdate."|".$f_nick."|".$f_stuffsaid."|".$personsitefinal."|".$ip."|"."\n";
$test_last = file($talkdatafile);
$test_lastr = array_reverse($test_last);
$last_e = $test_lastr[0];
if($writedata != $last_e){
fwrite ($t_fp, $writedata);
fclose ($t_fp);
}
}
}
}
} else {
if ($action == "talk") {
if(strlen($nick) >= 0){
if(strlen($stuffsaid) >= 0){
$t_fp = fopen ($talkdatafile, "a+");
$talkdate = date("H:i d/m/y");
$ip = getenv(REMOTE_ADDR);
$nicktwo = ereg_replace('<', ' ', $nick);
$nickthree = ereg_replace('>', ' ', $nicktwo);
$one_stuffsaid = ereg_replace('<', ' ', $stuffsaid);
$two_stuffsaid = ereg_replace('>', ' ', $one_stuffsaid);
$f_stuffsaid = stripslashes("$two_stuffsaid");
$f_nick = stripslashes("$nickthree");
$writedata = $talkdate."|".$f_nick."|".$f_stuffsaid."|".$ip."|"."\n";
$test_last = file($talkdatafile);
$test_lastr = array_reverse($test_last);
$last_e = $test_lastr[0];
if($writedata != $last_e){
fwrite ($t_fp, $writedata);
fclose ($t_fp);
}
}
}
}
}
//EDIT THESE VARS
$bgcolor = "black";
$bordercolor = "red";
$height = "300";
$width = "500";
$font = "verdana";
$fontcolor = "red";
$linkcolor = "#CC0000";
$linkhover = "red";
$inputtext = "red";
$inputbackground = "#000000";
$inputborder= "#FF0000";
//DONT EDIT
echo "<html><head>\n"
."<style type=text/css></style></head>\n"
."<style type=text/css>\n"
."<!--\n"
."a:link.taglink{color:$linkcolor;font-family:$font;}\n"
."a:visited.taglink{color:$linkcolor;font-family:$font;}\n"
."a:hover.taglink{color:$linkhover;font-family:$font;}\n"
."input.tagput{color:$inputtext;font-family:$font;background-color:$inputbackground;border-color:$input-border;border-style:solid;border-width:1}\n"
."-->\n"
."</style>\n"
."<body bgcolor=$bgcolor topmargin=0 leftmargin=0>\n"
."<table border=0 cellpadding=0 cellspacing=0 bgcolor=$bgcolor>\n"
."<tr><td colspan=2>";echo "<table border=0 cellpadding=0 cellspacing=0 bgcolor=$bgcolor>\n"
."<tr><td>\n";echo "<table border=1 cellpadding=0 cellspacing=0 bordercolor=$bordercolor><tr><td bordercolor=$bgcolor>\n"
."<ilayer name=\"scroll1\"><div id=\"scroll3\" style=\"width:$width;height:$height;background-color:$bgcolor;overflow:auto\" valign=\"bottom\"><font face=$font color=$fontcolor size=1>\n";
$talks_temp = file($talkdatafile);
$talks = array_reverse($talks_temp);
$showtalks = count($talks);
if($sfeature == "1"){
for ($t = 0; $t < $showtalks; $t++) {
$talk_array = explode("|", $talks[$t]);
echo "".$talk_array[1].": ";
echo $talk_array[2]."
\n";
}
} else {
for ($t = 0; $t < $showtalks; $t++) {
$talk_array = explode("|", $talks[$t]);
echo "".$talk_array[1].": ";
echo $talk_array[2]."
\n";
}
}
echo "</tr></td></table>\n"
."</textarea>\n"
."</div>\n"
."</font>\n"
."</td></tr>\n"
."</table>\n"
."</table>\n"
."<table cellpadding=0 cellspacing=3><tr><td>\n"
."<form action=\"".$PHP_SELF."\" method=\"post\">\n"
."<tr><td><font face=$font color=$fontcolor size=1>Nick: $nick <input name=\"nick\" type=\"hidden\" value=\"$nick\" class=tagput><td><input type=\"text\" name=\"stuffsaid\" class=tagput size=\"80\"> <input type=\"submit\" name=\"tagit\" value=\"invia\" class=tagput>
";
if($sfeature == "1"){
echo "<tr><td><font face=$font color=$fontcolor size=1>Site:<td><input type=\"text\" name=\"personsite\" value=\"http://\" class=tagput>
";
} else {
echo "";
}
echo "</table>\n"
."<input type=\"hidden\" name=\"action\" value=\"talk\">\n"
."</form>\n"
."</font>\n"
."</body>\n"
."</html>";
}
tg($action, $nick, $stuffsaid, $personsite);
/* made by dan - ice-on-fire.net */
?>
Come faccio a risolvere questo problema?? pensavo a un Javascript o qualcosa di simile...