Code: Alles auswählen
chat.php
<?php
$site_body.=
<table class=contentbody width=100% cellspacing=1 cellpadding=4><tr>
<td class=heads>ChatZone</td></tr></table>
<center>
<iframe src=chat/cz_chat.php?action=enter&nick=$USER[nick]&chat=betritt den Chat width=100% height=400 frameborder=0 scrolling=no></iframe>
</center>
;
?>
cz_chat.php
<?
// Datenbank schreibe
$dhost = bla; // hostname
$dbuser = bla; // user
$dpw = bla; // paßwort
$dbname = bla; // Datenbankname
$db = @mysql_connect($dhost,$dbuser,$dpw);
mysql_select_db($dbname);
$linec = 3;
if (empty($action))
ShowLoginForm();
elseif ($action == posts)
ShowAddPosts();
elseif ($action == form)
GetInput();
elseif ($action == enter)
Login();
function ShowLoginForm() {
?>
<body bgcolor=#CCCCCC>
[b]Wähle deinen nickname[/b]
<form name=chat method=post action=cz_chat.php target=_top>
<input type=text name=nick size=20>
<input type=hidden name=action value=enter>
<input type=hidden name=chat value=<font color=FF0000>[b]betritt den Raum um <? echo date(H:i); ?>[/b]</font>>
<input type=submit name=Submit value=und los!>
</form>
<?
}
function Login() {
global $HTTP_SESSION_VARS;
global $chat;
global $nick;
session_start();
session_register(nick, $nick);
?>
<frameset rows=*,55 cols=* noresize>
<frame name=posts src=cz_chat.php?action=posts&nick=<? echo $nick; ?>&chat=<?php echo $chat; ?>noresize>
<frame name=form src=cz_chat.php?action=form&nick=<? echo $nick; ?>scrolling=no noresize>
</frameset>
<noframes>
<body>
<p>Diese Seite benötigt Frames die Ihr Brwoser leider nicht unterstützt.</p>
</body>
</noframes>
</frameset>
<?
}
function GetInput() {
global $HTTP_SESSION_VARS;
global $chat;
global $nick;
?>
<body bgcolor=#0073EA>
<table border=0 width=100%><tr><td>
<form onSubmit=return doSubmit name=chatform method=post action=cz_chat.php target=posts>
<input type=text name=chat size=40>
<input type=hidden name=nick value=<? echo $nick; ?>>
<input type=button onClick=doSubmit() name=Submit value=Los!>
<input type=image src=lachen.gif name=DoFace1 value= :) onClick=sendFace(1)>
<input type=image src=sauer.gif name=DoFace2 value= :( onClick=sendFace(2)>
<input type=image src=grinz.gif name=DoFace3 value= :D onClick=sendFace(3)>
<input type=image src=cool.gif name=DoFace4 value= :-) onClick=sendFace(4)>
<select name=col>
<option name=Black>schwarz</option>
<option name=Red>rot</option>
<option name=Green>grün</option>
<option name=Blue>blau</option>
<option name=Orange>orange</option>
</select>
</td>
</tr></table>
<input type=hidden name=action value=posts>
</form>
<script language=JavaScript>
function sendFace(faceNum)
{
switch(faceNum)
{
case 1:
document.chatform.chat.value = ':)';
break;
case 2:
document.chatform.chat.value = ':(';
break;
case 3:
document.chatform.chat.value = ':D';
break;
case 4:
document.chatform.chat.value = ':-)';
break;
}
document.chatform.submit();
document.chatform.chat.value = '';
}
function doSubmit()
{
if(document.chatform.chat.value == '') {
alert('Bitte Text eingeben!');
document.chatform.chat.focus();
return false;
}
document.chatform.chat.value = '<font color='+document.chatform.col[document.chatform.col.selectedIndex].name+'>'+document.chatform.chat.value+'</font>';
document.chatform.submit();
document.chatform.chat.value = '';
document.chatform.chat.focus();
return true;
}
</script>
<?
}
function ShowAddPosts() {
global $HTTP_SESSION_VARS;
global $chat;
global $nick;
echo '<meta http-equiv=refresh content=10;URL=cz_chat.php?action=posts&nick=<? echo $nick; ?>>';
if(!empty($chat)) {
$strQuery = insert into cz_chat values(0, '$chat', '$nick');
mysql_query($strQuery);
}
$strQuery = select texta, nick from cz_chat order by id desc limit 20;
$chats = mysql_query($strQuery);
while($chatline = mysql_fetch_array($chats)) {
echo [b] . $chatline[nick] . :[/b] . swapFaces($chatline[texta]) . ;
}
$query = select * from cz_chat;
$result = mysql_query($query);
$num = mysql_num_rows($result);
if ($num >= 10){
$querykilla = delete from cz_chat;
$resultkilla = mysql_query($querykilla);
}
}
function swapFaces($chatLine) {
$chatLine = str_replace(:), [img]lachen.gif[/img]
$chatLine = str_replace(:(, [img]sauer.gif[/img]
$chatLine = str_replace(:D, [img]grinz.gif[/img]
$chatLine = str_replace(:-), [img]cool.gif[/img]
return $chatLine;
}
?>
<!--
// --------------------------------------------------------------------------
// Dokumentationshinweise:
// Programmname : codezilla.at chat v1.0
// Programmtyp : JavaScript + PHP 4
// Autor : Essl.Bernhard
// Kontakt : [email]admin@codezilla.at[/email]
// Erstellt am : 2002 11 06
// Zweck : Chat
// Dieses Skript darf weitergegeben werden solange die Dokumentationshinweise
// erhalten bleiben!
// In diesen Fall wäre es auch nett das Logo stehen zulassen,
// ist aber nicht zwingend :)
// Besuchen Sie [url]www.codezilla.at[/url] um weitere freie Skripte zu finden!
// --------------------------------------------------------------------------
-->