一,聊天室模块实现
1,聊天室主页面窗口设置
代码如下:
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!--载入配置文件-->
<?php include_once 'config.php';?>
<!--页面标题-->
<title><?php echo CHAT_NAME; ?></title>
<script language="javascript" src="main.js"></script>
<frameset rows="80,*,100" cols="*" frameborder="yes" border="1" framespacing="0">
<!--顶部窗口-->
<frame src="top.php" name="topFrame" scrolling="No" noresize="noresize" id="topFrame" title="topFrame" />
<frameset rows="*" cols="168,*" framespacing="0" frameborder="yes" border="1">
<!--左侧窗口-->
<frame src="list.php" name="leftFrame" scrolling="No" id="leftFrame" title="leftFrame" />
<frameset rows="70%,*" cols="*" framespacing="0" frameborder="yes" border="1">
<!--公共聊天窗口-->
<frame src="center.php" scrolling="auto" name="mainFrame" noresize="noresize" id="mainFrame" title="mainFrame" />
<!--私聊窗口-->
<frame src="private.php" scrolling="auto" name="priFrame" id="priFrame" title="priFrame" />
</frameset>
</frameset>
<!--发言窗口-->
<frame src="talk.php" name="bottomFrame" scrolling="No" noresize="noresize" id="bottomsFrame" title="bottomFrame" />
</frameset>
<noframes>
<body></body>
</noframes>
2,文件操作函数
本聊天室模块使用文本来保存用户列表和发言信息,主要考虑对文件的操作在速度上要优于对数据库的操作。
(1)fopen()函数,打开文件或者URL,如果打开失败,函数返回FALSE
语法:fopen(filename,mode,include_path,context)
参数说明:
filename:必须,规定要打开的文件或URL
mode:必须,规定要求到该文件/流的访问类型。
include_path:可选,如果也需要在include_path中检索文件的话,可以将该参数设为1或TRUE。
context:可选。规定文件句柄的环境,context是可以修改流的行文的一套选项
mode参数的取值:
"r":只读方式打开,将文件指针指向文件头。
"r+":读写方式打开,将文件指针指向文件头。
"w":写入方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建。
"w+":读写方式打开,将文件指针指向文件头并将文件大小截为零。如果文件不存在则尝试创建。
"a":写入方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建。
"a+":读写方式打开,将文件指针指向文件末尾。如果文件不存在则尝试创建。"x":创建并以写入方式打开,文件指针指向文件头。如果文件已存在,则fopen()调用失败并返回FALSE,并生成一条E_WARNING级别的错误信息。如果文件不存在则尝试创建。"x+":创建并以读写方式打开,将文件指针指向文件头。如果文件已存在,则fopen()调用失败并返回FALSE,并生成一条E_WARNING级别的错误信息。如果文件不存在则尝试创建。
新闻热点
疑难解答