PHP设计聊天室步步通(二)
登录
1、页面登陆的基本要素
你可以在我的竹叶看到登陆的表单,这里提供了最基本的登陆表单项
(1)登陆表单
<form method = POST name = chatform action = chat /login.php? action = enter onSubmit = "b1_submit();return true;" target = "howtodo" >(a)聊天表单的名字为chatform,我使用action=enter作为进入聊天室的入口,如果没有这个参数,则显示登陆页面.
(b)在表单提交时,先调用b1_submit()建立聊天的窗口
(c)聊天的目标窗口为b1_submit()建立的howtodo窗口
(2)表单项
昵称:<input type=text name=name size=15 maxlength="10">
密码:<input type=passWord name=pass size=15 maxlength="10">
<input type=submit name=submit value=登陆 style="width:100">
<input type=reset name=reset value=重添 style="width:50">
(a)各表单项一定要设定最大允许长度 maxlength
(3)建立聊天窗口的js
<script LANGUAGE= "javascript" > function b1_submit(){ chat=window.open( '' , "howtodo" , 'Status=no,scrollbars=no,resizable=no' ); chat.moveTo(0,0); chat.resizeTo(screen.availWidth,screen.availHeight); chat.outerWidth=screen.availWidth; chat.outerHeight=screen.availHeight; }这段代码先打开一个没有状态栏,滚动条,可调整尺寸的howtodo窗口!然后移动到屏幕左上角,然后放大到允许的屏幕大小.
在线人数
我根据网易聊天室的在线人数的方法,显示当前的在线人数,代码解释如下:
1、登陆时建立在线人名单的数组,放在body后面
<? //锁定在线人数文件 while ( file_exists ( $useronlinelock )){ $pppp ++;} fclose( fopen ( $useronlinelock , "w" )); //读入在线人名单 $useronline = file( $useronline ); unlink( $useronlinelock ); //建立数组 list print( "document.writeln(" list= new Array("); $k = count ( $useronline ); if ( $k >1) { for ( $i =0; $i <( $k -1); $i ++) { $usercurrent = split( $split , $useronline [ $i ],99); // 姓名+, print( "'$usercurrent[0]'," ); } $i = $k -1; // 处理最后一个姓名 $usercurrent = split( $split , $useronline [ $i ],99); print( "'$usercurrent[0]'" ); } // 数组结束 print( ")" );n"); ?>2、显示在线人数的js
document.writeln( '[在线人数<font color=red>' +count+ '</font>]<br>' ); document.writeln( "[<a href=" Javascript:parent.cs( '所有人' )">所有人</ a>]<br>"); document.writeln( "<font class='p9'>" ); var j,name,club; for ( var i=0;i<list.length;i=i+1) { if (list[i]!= null ){ //显示每个在线人的名字 document.writeln( "<a href=" javascript:parent.cs( '"+list[i]+"' )" titl e= '"+list[i]+"' > "+list[i]+" </a><br>"); } } this .r.document.writeln( '</font><hr>' );3、改变聊天对象
function cs(name) { if ( this .d.document== null ) return ; if (name== '所有人' ) { this .d.add( '所有人' ); this .d.document.inputform.talkto.value= '所有人' ; //改变焦点 this .d.document.inputform.msg.focus(); return ; } for ( var i=0;i<list.length;i=i+1) { if (list[i]==name) { //更改发送的谈话对象 this .d.document.inputform.talkto.value=list[i]; this .d.document.inputform.msg.focus(); return ; } } //错误 alert( '此用户已离线或已改了昵称。' ); }查看更多关于PHP设计聊天室步步通(二) - 综合实例的详细内容...