多人聊天室。双人聊天室后面再加
2021/4/11 10:57:16
本文主要是介绍多人聊天室。双人聊天室后面再加,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
calls=array( 'id' => null, 'nid' => null, 'name' => '', 'cur_time' => '', 'context' => '', 'switch' => '', ); //用户 $this->user=array( 'nid'=>null, 'name'=> '', ); //注册 $this->us_login = array( 'name' => array('老王','锅巴','pp'), ); } public function edit(){ $this->us_login?$this->us_login:$this->user; if(!$this->us_login) die('非法操作'); $coun=count($this->user['nid']); if ($this->user['nid']==null) { unset($this->user['nid'],$this->user['name']); $users=array( 'nid'=> 0, 'name'=> $this->us_login['name'][0], ); array_push($this->user,$users); } return $this->user; } //新增 public function add(){ $coun = count($this->user); $coun2 = count($this->us_login['name']); for ($i = 0; $i < $coun2; $i++) { $users=array( 'nid'=> $i, 'name'=> $this->us_login['name'][$i], ); array_push($this->user,$users); unset($this->user[0]); } sort($this->user); } /** * 传nid给方法验证用户 * 格式 */ public function add_mes($name){ //pp $user=$this->user; //登录 for ($i = 0; $i < count($user); $i++) { if($user[$i]['name']==$name){ $this->nid=$user[$i]['nid']; $this->name=$user[$i]['name']; $suss=1; } } if ($suss !=1) { exit('code:-1,msg:没有登录'); } $token=md5(rand(1,100)); return $token; } //写数据 public function add_mes_wr($context,$name) { $coun=count($this->calls['id']); $coun+=1; $calls['id'] =''; $calls['nid'] = $this->nid; $calls['name'] = $name; $calls['cur_time'] = time(); $calls['context']= $context; $calls['switch'] = ''; if ($coun) { $calls['id']=$coun; } array_push($this->calls,$calls); $c=$this->calls; unset($c['id'],$c['nid'],$c['name']); unset($c['cur_time'],$c['context'],$c['switch']); return $c; } } $call = new Call(); $data=$call->edit(); $call->add(); $name1='老王'; $name2='锅巴'; $token =$call->add_mes($name1); $token1=$call->add_mes($name2); if (!$token&&$token1) { exit('code:-1,msg:未登录'); } //开始聊天 $c=$call->add_mes_wr('你好',$name1); sleep(3); $c=$call->add_mes_wr('有人吗?',$name2); //时间 name 内容 $kg=' '; foreach ($c as $v) { $date=date('Y/m/d h:i:s',$v['cur_time']); echo $date.$kg.$v['name'].':'.$kg.$v['context']."\n"; }这篇关于多人聊天室。双人聊天室后面再加的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-28一步到位:购买适合 SEO 的域名全攻略
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign服务间调用学习入门
- 2024-12-27OpenFeign学习入门:轻松掌握微服务通信
- 2024-12-27OpenFeign学习入门:轻松掌握微服务间的HTTP请求
- 2024-12-27JDK17新特性学习入门:简洁教程带你轻松上手
- 2024-12-27JMeter传递token学习入门教程
- 2024-12-27JMeter压测学习入门指南
- 2024-12-27JWT单点登录学习入门指南
- 2024-12-27JWT单点登录原理学习入门