Tags:
php
Jeg har en chat men som bare mangler en ting lige nu og det er en onlineliste så man kan se hvem der er online på chatten
jeg sender her alle mine chat filer. så vis en vil lave en komplet online liste som opdateres når en logger af og logger på for du 60 point....
der er følgende filer til chatten....
-index.php
-chat.php
-config.php
-login.php
-logout.php
-msg.php
----------------------------------------------------------------------------
index.php
----------------------------------------------------------------------------
<?
include ( "config.php" );
unset( $user_name );
session_start();
if ( !isset($user_name) || $user_name=="" ) Header ( "Location: login.php" );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>......Joy Palaze Entertainment......</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
td {
font-family: verdana, arial, sans-serif;
font-size: 11px;
}
.msgTbl {
width: 100%;
}
td, input, button {
font-family: verdana, arial, sans-serif;
font-size: 11px;
}
input {
width: 100%;
border: 1px dashed #336699;
}
button {
background-color: #dedede;
border: 1px solid #336699;
margin-left: 15px;
}
.u {
width: 100px;
color: #ff0000;
vertical-align: top;
padding: 5px 12px 5px 5px;
border-bottom: 1px dashed #999999;
}
.m {
padding: 5px;
border-bottom: 1px dashed #999999;
}
.time {
color: #336699;
font-size: 9px;
}
.clHidFrame {
position: absolute;
width: 1px;
height: 1px;
left: 0px;
top: 0px;
}
#chat {
width: 450px;
}
</style>
<script type="text/JavaScript">
var maxNumMsgs = <?=$maxNumMsgs?>;
var hiCol = "<?=$hiCol?>";
var loCol = "<?=$loCol?>";
var d=document;
function gE(id){return d.getElementById(id)}
function gA(o,tN){return o.getElementsByTagName(tN)}
function writeChat( a ) {
var tbl = gE("chat");
for (i=0; i<a.length; i+=3) {
var bgCol = ( gA(tbl, "TR")[0].style.backgroundColor=="#ffffff" )? loCol : hiCol;
var newRow = tbl.insertRow(0);
var newCell = newRow.insertCell(0);
newCell.innerHTML = "<b>" + a + "</b><div class=\\"time\\">[" + a[i+1] + "]</div>";
newCell.className = "u";
var newCell = newRow.insertCell(1);
newCell.innerHTML = a[i+2];
newCell.className = "m";
newRow.style.backgroundColor = bgCol;
}
var numMsgs = gA(tbl, "TR").length;
while ( numMsgs>maxNumMsgs ) {
tbl.deleteRow(numMsgs-1);
numMsgs--;
}
}
window.onunload = function() {
window.open( "logout.php", "logOutWin", "width=100,height=100" );
}
</script>
</head>
<body>
<div style="width:470px">
<div id="bla" style="height:250px;overflow:auto;">
<table id="chat" cellspacing="0" cellpadding="0" border="0">
<tr>
<td colspan="2"> </td>
</tr>
</table>
</div>
<form name="msgForm" target="msgFrame" action="msg.php" method="post">
<table class="msgTbl" cellspacing="0" cellpadding="0" border="0">
<tr>
<td><input type="text" name="msg"></td>
<td style="width:10px;"><button type="submit">Send</button></td>
</tr>
</table>
</form><a href="logout.php">Forlad Chatten</a>
</div>
<iframe name="msgFrame" class="clHidFrame" src="msg.php" frameborder="0"></iframe>
<iframe name="chatFrame" class="clHidFrame" src="chat.php" frameborder="0"></iframe>
</body>
</html>
----------------------------------------------------------------------------
chat.php
----------------------------------------------------------------------------
<?
include ( "config.php" );
if ( !isset($s) || $s=="" ) $s = 0;
$sql = "select * from messages where stamp>'$s' order by stamp";
$res = mysql_query( $sql ) or die (mysql_error());
$num_rows = mysql_num_rows( $res );
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<script type="text/JavaScript">
var a = new Array();
<?
if ($num_rows>0) {
while ( $row=mysql_fetch_array($res) ) {
$arr_str .= "a[a.length] = \\"".stripslashes($row["user"])."\\";\\n";
$arr_str .= "a[a.length] = \\"".date( "H:i:s", $row["stamp"] )."\\";\\n";
$arr_str .= "a[a.length] = \\"".stripslashes($row["msg"])."\\";\\n";
$s = $row["stamp"];
}
print $arr_str;
}
?>
parent.writeChat( a );
setTimeout( "location.href='chat.php?s=<?=$s?>'", 5000 );
</script>
</html>
----------------------------------------------------------------------------
config.php
----------------------------------------------------------------------------
<?
# ------------------------------------------
# Server variables
$db_server = "localhost";
$db_user = "xxxxxx";
$db_pass = "xxxxxx";
$db_db = "xxxxxx";
# ------------------------------------------
# The longest time messages are kept in DB
$maxAge = 60*10; // seconds
# ------------------------------------------
# Variables used for rendering of messages
$maxNumMsgs = 50; // Max numbers of lines showed
$hiCol = "#ffffff"; // Highlight row-color
$loCol = "#ededed"; // Lolight row-color
# ==========================================
# Functionality used globaly (don't alter)
$connection = mysql_connect($db_server, $db_user, $db_pass) or die (mysql_error());
$do_connect = mysql_select_db($db_db, $connection) or die (mysql_error());
if ( !empty($_SESSION) ) {
extract($_SESSION);
} else if ( !empty($HTTP_SESSION_VARS) ) {
extract($HTTP_SESSION_VARS);
}
if ( !empty($_GET) ) {
extract($_GET);
} else if ( !empty($HTTP_GET_VARS) ) {
extract($HTTP_GET_VARS);
}
if ( !empty($_POST) ) {
extract($_POST);
} else if ( !empty($HTTP_POST_VARS) ) {
extract($HTTP_POST_VARS);
}
?>
----------------------------------------------------------------------------
login.php
----------------------------------------------------------------------------
<?
session_start();
include ( "config.php" );
if ( isset($user) && $user<>"" && strlen($user)<=15 ) {
$user = addslashes( $user );
$sql = "insert into users set user='$user'";
$res = mysql_query( $sql );
if ( mysql_affected_rows()>0 ) {
$msg = "<b>Ny bruger logget på</b>";
$stamp = time();
$sql = "insert into messages ( user, msg, stamp ) values ( '$user', '$msg', '$stamp' )";
mysql_query( $sql );
session_register( "user_name" );
$user_name = $user;
Header("Location:./index.php");
} else {
$err_msg = "<div style=\\"color:#ff0000;font-weight:bold;text-align:center;\\">Dette nick er allerede optaget</div>";
}
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title> ..:: LogIn ::.. </title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
div, input, button {
font-family: verdana, arial, sans-serif;
font-size: 11px;
}
input {
width: 200px;
border: 1px dashed #336699;
}
button {
background-color: #dedede;
border: 1px solid #336699;
margin-left: 15px;
}
</style>
<script type="text/JavaScript">
var d=document;
function checkForm(f) {
if ( f.user.value=="" ) {
alert("Du skal skrive et chat-nick");
return false;
}
if ( f.user.value.length>15 ) {
alert("Dit chat-nick må højest være på 15 tegn");
return false;
}
}
</script>
</head>
<body>
<div style="padding-top:120px;" align="center">
<?=$err_msg?>
<b>Skriv dit chat-nick og tryk 'LogIn':</b>
<form action="login.php" method="post" onsubmit="return checkForm(this)">
<input type="text" name="user">
<button type="submit">LogIn</button>
</form>
</div>
<script type="text/JavaScript">d.forms[0].user.focus();</script>
</body>
</html>
----------------------------------------------------------------------------
logout.php
----------------------------------------------------------------------------
<?
include ( "config.php" );
unset( $user_name );
session_start();
if ( isset($user_name) ) {
$msg = "<b>Bruger logget af</b>";
$stamp = time();
$sql = "insert into messages ( user, msg, stamp ) values ( '$user_name', '$msg', '$stamp' )";
mysql_query( $sql );
$sql = "delete from users where user='$user_name'";
mysql_query( $sql );
session_unset();
session_destroy();
}
print "<script type=\\"text/JavaScript\\">window.close();</script>";
?>
----------------------------------------------------------------------------
msg.php
----------------------------------------------------------------------------
<?
include ( "config.php" );
unset( $user_name );
session_start();
if ( isset($msg) && $msg<>"" && $user_name ) {
$replArr = array(
"<" => "<",
">" => ">",
"\\"" => "'",
"--" => ""
);
strtr( $msg, $replArr );
$msg = addslashes( $msg );
$stamp = time();
$sql = "insert into messages ( user, msg, stamp ) values ( '$user_name', '$msg', '$stamp' )";
mysql_query( $sql );
$oldStamp = $stamp - $maxAge;
$sql = "delete from messages where stamp<$oldStamp";
mysql_query( $sql );
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<script type="text/JavaScript">
parent.d.forms[0].msg.value = "";
parent.d.forms[0].msg.focus();
</script>
</html>
----------------------------------------------------------------------------
Håber i vil hjælpe mig med at lave den onlineliste til min chat...
på forhånd tak for hjælpen....
hilsen joy_palaze
1 svar postet i denne tråd vises herunder
0 indlæg har modtaget i alt 0 karma
0
Kunne man få lov at se din database strukturen?