📄 chat.php
字号:
<?php ob_start();
$user=$_COOKIE['username'];
include "Sysconf.php";//连接数据库$refresh=15;//刷新间隔
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $refresh?>" >
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
textarea,font,center{
background-color : ##FFF8DC;
color : #1E90FF;
font-family : Trebuchet MS;
}
.test{font-size: 10pt;color:red; text-decoration:underline}
</style>
<script>
function check(){
var c = document.getElementById("textinput");
if(c.value!=""){
var sel = document.getElementById("sl");
if(sel.length!=0){
return true;
}else{
alert("当前没有用户在线!");
c.focus();
return false;
}
}else{
alert("内容不能为空!");
c.focus();
return false;
}
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = ": expires="+date.toGMTString();
}
else
var expires = "";
document.cookie = name+"="+value+";"+expires+";";
}
function getCookie(Key){
var search = Key + "=";
begin = document.cookie.indexOf(search);
if (begin != -1) {
begin += search.length;
end = document.cookie.indexOf(";",begin);
if (end == -1) end = document.cookie.length;
return document.cookie.substring(begin,end);
}
}
function save(){
createCookie("original",escape(tt),0);
}
function eraseCookie(name) {
createCookie(name,"",-1);
}
function getLoad(){
if(typeof(getCookie('cc'))!='undefined'){
document.getElementById('textinput').value=getCookie('cc');
}
//document.getElementById('textinput').focus();
}
function FP_swapImg() {//v1.0
var doc=document,args=arguments,elm,n; doc.$imgSwaps=new Array(); for(n=2; n<args.length;
n+=2) { elm=FP_getObjectByID(args[n]); if(elm) { doc.$imgSwaps[doc.$imgSwaps.length]=elm;
elm.$src=elm.src; elm.src=args[n+1]; } }
}
function FP_preloadImgs() {//v1.0
var d=document,a=arguments; if(!d.FP_imgs) d.FP_imgs=new Array();
for(var i=0; i<a.length; i++) { d.FP_imgs[i]=new Image; d.FP_imgs[i].src=a[i]; }
}
function FP_getObjectByID(id,o) {//v1.0
var c,el,els,f,m,n; if(!o)o=document; if(o.getElementById) el=o.getElementById(id);
else if(o.layers) c=o.layers; else if(o.all) el=o.all[id]; if(el) return el;
if(o.id==id || o.name==id) return o; if(o.childNodes) c=o.childNodes; if(c)
for(n=0; n<c.length; n++) { el=FP_getObjectByID(id,c[n]); if(el) return el; }
f=o.forms; if(f) for(n=0; n<f.length; n++) { els=f[n].elements;
for(m=0; m<els.length; m++){ el=FP_getObjectByID(id,els[n]); if(el) return el; } }
return null;
}
</script>
<base target="_self">
</head>
<body background='moren/rep_1.jpg' onUnload="createCookie('cc',document.getElementById('textinput').value,1)" onLoad="FP_preloadImgs(/*url*/'moren/buttonB1.jpg', /*url*/'moren/buttonC1.jpg', /*url*/'moren/buttonE2.jpg', /*url*/'moren/buttonF2.jpg', /*url*/'moren/buttonFE.jpg', /*url*/'moren/buttonFF.jpg'); getLoad()" link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF">
<center>即 时 聊 天 <br>
<textarea cols="28" rows="7" id="ta" onChange="save()"></textarea>
<form name=mm action=chat.php method="post">
<input type=hidden name=hh value="">
<table>
<tr>
<td width="54">聊天人:</td>
<td><select name=contact id=sl></select></td>
</tr>
<tr>
<td width="54">内容:</td>
<td><input name=content type=text id="textinput" size="16" maxlength="16" tabindex="1"></td>
</tr>
<tr align="">
<td width="54">
<!--<input type=image onclick="return check()" style="background:url(moren/button.jpg)"></td>-->
<input type=image onClick="this.form.hh.value='fasong'; return check()" border="0" id="img8" src="moren/buttonFD.jpg" height="20" width="40" alt="发送" onMouseOver="FP_swapImg(1,0,/*id*/'img8',/*url*/'moren/buttonFE.jpg')" onMouseOut="FP_swapImg(0,0,/*id*/'img8',/*url*/'moren/buttonFD.jpg')" onMouseDown="FP_swapImg(1,0,/*id*/'img8',/*url*/'moren/buttonFF.jpg')" onMouseUp="FP_swapImg(0,0,/*id*/'img8',/*url*/'moren/buttonFE.jpg')" fp-style="fp-btn: Corporate 4; fp-font; fp-proportional: 0" fp-title="发送"></td>
<td>
<input type=image border="0" id="img2" onClick="document.getElementById('textinput').value='';document.getElementById('ta').value=''; return false;"src="moren/buttonD2.jpg" height="20" width="40" alt="清空" onMouseOver="FP_swapImg(1,0,/*id*/'img2',/*url*/'moren/buttonE2.jpg')" onMouseOut="FP_swapImg(0,0,/*id*/'img2',/*url*/'moren/buttonD2.jpg')" onMouseDown="FP_swapImg(1,0,/*id*/'img2',/*url*/'moren/buttonF2.jpg')" onMouseUp="FP_swapImg(0,0,/*id*/'img2',/*url*/'moren/buttonE2.jpg')" fp-style="fp-btn: Corporate 4; fp-font; fp-proportional: 0" fp-title="清空"></td>
</tr>
</table>
</form>
<?php
if($_POST['hh']=="fasong"){//对于用户发送的消息,存入数据库
$receiver= $_POST["contact"];
$content=$_POST["content"];
$mysql="insert into short_message values('".$content."','".$user."','".$receiver."',0)";
mysql_query($mysql);
}
$sql="select * from short_message where receiver='".$user."' or sender='".$user."' and isRead!=2";
$result=mysql_query($sql);
$all="'";
if($result == true){//显示所有接收和发送的消息
while($row=mysql_fetch_array($result,MYSQL_ASSOC)) {
$sender=$row['sender'];
$content=$row['content'];
$receiver=$row['receiver'];
if($sender==$user){
$all=$all."你对".$receiver."说:".$content.'\n';
}else
$all = $all.$sender."对你说:".$content.'\n';
}
echo "<script>document.getElementById('ta').value+=".$all."'</script>";
$sql="update short_message set isRead=1 where receiver='".$user."'";
mysql_query($sql);
}
$r=rand(1,40);//随机显示一些图片
echo "<a href=image/80/$r.JPG target=right class=test><img src=image/80/$r.JPG width=90% height=45% title=点击看大图></a></center>";
$tt=time();//更新在线数据库的访问时间
$sql="update online set last_access=".$tt." where user='".$user."'";
mysql_query($sql);
$sql="select * from online";
$result=mysql_query($sql);
// 更新在线用户
echo "<script>";
for($i=0,$p=0;$i<mysql_num_rows($result);$i++){
$t = mysql_result($result,$i,"user");
if($t!=$user){
echo "var op= new Option('$t');
document.getElementById('sl').options[".$p++."]=op;";
}
}
echo "</script>";
?>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -