有个关于 php 文件处理方面的问题
问题就是 现在做了一个简单的聊天室。然后要求我们的是 聊天室添加一个功能就是只显示1小时之内的聊天内容 想了很久还是想不到什么方法可以做到。来此求助 求大大们轻喷下面是我的两段代码 包括login和chat
login.htm
程序代码:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <TITLE> 用户登录 </TITLE> </HEAD> <BODY> <script language="javascript"> function check(f) { if(f.user.value == "") { alert("请输入用户名称!"); f.user.focus(); return (false); } if (f.pass.value == "") { alert("请输入用户密码!"); f.pass.focus(); return (false); } if ( f.pass.value.length<6 ) { alert("密码不得小于6位!"); f.pass.focus(); return (false); } } </script> <style type="text/css"> <!-- tr,td{font-size:10pt} --> </style> <center> <H3>用户登录</H3> <TABLE border="1" cellspacing="0" cellpadding="1" bordercolordark="#ffffff" bordercolorlight="#0000ff" width="280"> <FORM METHOD=POST ACTION="chat.php" onsubmit="return check(this)"> <TR> <TD colspan="2" align="center" bgcolor="#9999ff">输入登录内容</TD> </TR> <TR> <TD align="right" width=30%>用户名:</TD> <TD width=70%><INPUT TYPE="text" NAME="user" value="31101245"></TD> </TR> <TR> <TD align="right">密 码:</TD> <TD><INPUT TYPE="password" NAME="pass" size="21" value="123456"></TD> </TR> <TR> <TD colspan="2" align="center"> <INPUT TYPE="submit" value="登录"><INPUT TYPE="reset" value="重填"> </TD> </TR> </FORM> </TABLE> </center> </BODY> </HTML>
chat.php
程序代码:
<form id="form1" name="form1" method="post" enctype="mutipart/form-data"> <p>欢迎来聊天</p> <p> <label> <input name="talk" type="text" id="talk" size="50" maxlength="200" /> </label> <label> <input type="submit" name="say" id="say" value="发送" /> </label> <a href="login.htm">返回登录</a></p> <?php session_start(); @$check=$_POST['say']; if($_SESSION["user"]=='') $_SESSION["user"]=$_POST["user"]; if($check == "发送"){ $_SESSION["talk"]=$_POST["talk"]; date_default_timezone_set('Asia/Shanghai'); $date=date("Y-m-d H:i:s"); $sk=file_get_contents("records.txt"); $fp=fopen("records.txt","w"); $str =$date.' '.$_SESSION["user"]."说:".$_SESSION["talk"]."<br>"; $str=$str.$sk; fwrite($fp,$str); fclose($fp); } $fop=fopen("records.txt","r"); $mes=fgets($fop); echo $mes; fclose($fop); ?> </form>