您现在的位置: 军旅同心-旅游自驾-军旅文学 >> 读书赏析 >> 学习园地 >> 电脑网络 >> 技术文章 >> 正文
用PHP+MySql编写聊天室
作者:采集员 文章来源:来源于网络 点击数: 更新时间:2005-9-10 14:36:18
;
$sql="insert chat (username,objectname,action,msg,color) values ("$username","$objectname","NO","$fayan","$yanse")";
mysql_query($sql,$conid);
mysql_close($conid);
}
?>
<!--获取发言信息getmsg.php-->
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<?PHP  
$conid=mysql_pconnect("localhost","yourcount","password");
mysql_select_db("database",$conid);

if(!isset($username))
     $username="getmsg";  
$dt=time();   
$newdate=date("YmdHis",$dt);
$fromdate=date("YmdHis",$dt-6);;

$sql="select username as name,msg,action,objectname ,shijian,color from chat where shijian>="$fromdate"";
$res=mysql_query($sql,$conid);

echo "<meta http-equiv="Refresh" content="6,url=getmsg.php?username=$username" >n";
echo "</head>n";

echo "<script language="JavaScript">n";
echo "<!--n";
echo "var win=parent.frames[0]n";
echo "var doc=win.documentn";
echo "var divlin=doc.body.all("lin")n";

while(list($name,$msg,$action,$objectname,$shijian,$color)=mysql_fetch_row($res))
{
if($objectname!="大家"||$objectname) $object="对 <a href=JavaScript:selectusername('$objectname')>$objectname</a> ";
echo  "divlin.innerHTML=divlin.innerHTML+"<font color=$color size=3><a href=JavaScript:selectusername('$name')>$name</a> $object 说: $msg </font><br>"n";
}

echo "win.scrollBy(6000,6000)n";
echo "-->n";
echo "</script>n";
?>
<body bgcolor="#333333">
</body>

</html>
<!--欢迎词getmsg1.php -->
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<?PHP  
if(!isset($username))
     $username="guest";
echo "<meta http-equiv="Refresh" content="6;url=getmsg.php?username=$username" >n";
echo "</head>n";

echo "<script language="JavaScript">n";
echo "<!--hiden";
echo "var win=parent.frames[0]n";
echo "var doc=win.documentn";
echo "var divlin=doc.body.all("lin")n";
echo "divlin.innerHTML= "<font color=blue><b>欢迎 $username 的光临</b></font><br>"n";
echo "-->n";
echo "</script>n";
?>
<body bgcolor="#333333">
</body>
</html>
<!--显示发言list.html-->
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.lin {  font-size: 10pt; color: #FF6633}
-->
</style>
</head>
<body bgcolor="#FFFFFF" >
<center>
<div color=blue>
<font color=white size=6><b>
欢迎光临</b>
</marquee>
</div>
</center>
<div id=lin class="lin"></div>
</body>
<Script language="JavaScript">
<!--
function selectusername(str)
{
var win=parent.frames[3]
var doc=win.document
var form1=doc.body.all("fayanform")
form1.objectname.value=str
}
-->
</script>
</html>

<!--罗列在线人数-->
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta http-equiv="Refresh" content="60">
<style type="text/css">
<!--
.lin {  font-size: 10pt; color: #ff0066}
-->
</style>
</head>

<body bgcolor="#33ff00" >
<center class="lin"><b>
  在线人数 </b>
<hr>
<?PHP
if(!isset($username))
    $username="guest";
$dt=time();   
$newdate=date("YmdHis",$dt);
$fromdate=date("YmdHis",$dt-200);
$linkid=mysql_connect("localhost","yourcount","password");
mysql_select_db("yourdatabase",$linkid);
$sql="update chat_getmsg set shijian="$newdate" where username="$username"";
mysql_query($sql,$linkid);
$sql="select username from chat_getmsg where shijian>="$fromdate"";
$res=mysql_query($sql,$linkid);  
while(list($username)=mysql_fetch_row($res)){
     echo "<a href="JavaScript:selectusername('$username')">$username</a><br>n";
$fromdate=date("YmdHis",$dt-100);
$sql="delete from chat where shijian<="$fromdate"";
mysql_query($sql,$linkid);
mysql_close($linkid);
}
?>
</center>
<Script language="JavaScript">
<!--
function selectusername(str)
{
var win=parent.frames[3]
var doc=win.document
var form1=doc.body.all("fayanform")
form1.objectname.value=str
}
-->
</script>
</body>
</html>


【本文版权归作者与奥索网共同拥有,如需转载,请注明作者及出处】    

上一页  [1] [2] 


更多
免责声明:作品版权归所属媒体与作者所有!!本站刊载此文不代表同意其说法或描述,仅为提供更多信息。如果您认为我们侵犯了您的版权,请告知!本站立即删除。有异议请联系我们。
文章录入:烟灰缸    责任编辑:烟灰缸 
网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!)
| 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | 版权申明 | 网站公告 | 管理登录 |