PHP代码
- function chat_xzy()
- {
- if(!$totalnum=cache("chatMsgTotalNum")) $totalnum=cache("chatMsgTotalNum",1,3600*24*50);
- if(isset($_GET[‘ajax’]) && $_GET[‘ajax’]==‘userlist’){
- $json[‘data’]=getUserOL();
- $json[‘olusernum’]=olNum();
- echo json_encode($json);return true;
- }elseif($_GET[‘ajax’]==‘sendmsg’){
- $add[‘background’]=strip_tags($_POST[‘background’]);
- $add[‘color’]=strip_tags($_POST[‘color’]);
- $add[‘uid’]=$_SESSION[‘user’][‘uid’];
- $add[‘nickname’]=$_SESSION[‘user’][‘name’];
- $add[‘touid’]=$_POST[‘touid’];
- if(!emptyempty($add[‘touid’])){
- $a_=db("admin");
- $touser=$a_->id($add[‘touid’])->find();
- $add[‘tonickname’]=$touser[‘name’];
- }else{
- $add[‘tonickname’]=”;
- }
- $add[‘msg’]=strip_tags($_POST[‘msg’]);
- $add[‘time’]=date(‘m-d H:i:s’);
- $add[‘touid’]=$_POST[‘touid’];
- $totalnum++;
- cache("chatMsgTotalNum",$totalnum,3600*24*365);
- cache(‘chatMsgList’.$totalnum,$add,3600*24);
- $json[‘status’]=0;
- echo json_encode($json);return true;
- }elseif($_GET[‘ajax’]==‘showmsg’){
- if(!$mylastid=cache("chatMsgTotalMy".$_SESSION[‘user’][‘uid’])) $mylastid=cache("chatMsgTotalMy".$_SESSION[‘user’][‘uid’],1,3600*24);
- $n=$totalnum–$mylastid;
- $list=array();
- if($n>0){
- for($i=1;$i<=$n;$i++){
- $x=$mylastid+$i;
- $cTmp= cache(‘chatMsgList’.$x);
- if(emptyempty($cTmp[‘touid’]) || $cTmp[‘touid’]==$_SESSION[‘user’][‘uid’]) $list[]=$cTmp;
- }
- }
- cache("chatMsgTotalMy".$_SESSION[‘user’][‘uid’],$totalnum,3600*24);
- if(!emptyempty($list)){
- $json[‘data’]=$list;
- $json[‘status’]=0;
- }else{
- $json[‘status’]=1;
- }
- echo json_encode($json);return true;
- }
- $this->view();
- $mylastid=cache("chatMsgTotalMy".$_SESSION[‘user’][‘uid’],1,3600*24);
- }
效果: