Home php教程 php手册 php简单的在线聊天室程序

php简单的在线聊天室程序

May 25, 2016 pm 04:56 PM
fopen textarea

php教程简单的在线聊天室程序

index.php

<title>
在线聊天
</title>
<!-- frames -->
<frameset rows="70%,*" border="0">
    <frame name="top" src="_b.php" marginwidth="0" marginheight="0" scrolling="yes" frameborder="NO" noresize>
    <frame name="bottom" src="_a.php" marginwidth="0" marginheight="0" scrolling="no" frameborder="no" noresize>
</frameset>


Copy after login

 


_a.php

 class="brush:php;"><html>
<title>
聊天室
</title>
<body TOPMARGIN=0 LEFTMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0 >
<?php
$person = @$_POST[person];
$msg = @$_POST[message];
if ($person!="" && $msg!=""){
$handle = fopen("msg.txt","r");
$tot = 0;
$oldmsg = array();
while ($content = fgets($handle)){
    $oldmsg[] = $content;
    ++$tot;
}
fclose($handle);
unlink("msg.txt");
$fp = fopen("msg.txt","a+");
$time = date("h:i");
fwrite($fp,"<font color="blue">".$person."</font>&nbspin&nbsp<font color="red">".$time."</font>&nbsp&nbsps教程ays that&nbsp&nbsp<b>".$msg."</b><br>"."n");
for ($i =0;$i<$tot;++$i){
    if ($i>50) break;
    fwrite($fp,$oldmsg[$i]);
}
}

<TABLE width="100%" border="0" cellspacing="0" cellpadding="0">
<tr align="left" bgcolor="#666666">
<td height="20">
</td></tr>
<tr bgcolor="#FFCC66">
<td width="1" height="4" ></td>
</tr>
</TABLE>
<table width="100%" border=0 cellspacing=0 cellpadding=0 bgcolor="#EFEFEF">
<tr bgcolor="#666666">
<td align="left">
<table width="100%" height="500" boder=0 cellspacing=0 cellpadding=0 bgcolor="#EFEFEF">
<tr align="left">
<td valign="top">
<font size="-1" color="#666666">
 
<table width = "100%" border = "0">
    <tr>
    <form action="_a.php" method = "post">
        <td align="left">
        <font size="-1">昵称:</font>
        <input type="text" name="person" size="12" maxlength="80" value="<?php echo $person;">
        <br>
        <font size="-1"></font>
        <textarea type="textarea" name="message" rows="9" cols="150" size = 100></textarea>
        <input type="submit" value="发言">
        </td>
    </form>
    </tr>
</table>
</font>
</td>
</tr>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
Copy after login


_b.php

 class="brush:php;"><html>
    <head>
        <title>
        聊天室
        </title>
    </head>
    <META HTTP-EQUIV=Refresh CONTENT="5; URL=_b.php">
    <body bgcolor="#EFEFEF">
    <?php
        $handle=fopen("msg.txt","r");
        //$oldmsg = array();
        while ($content = fgets($handle)){
        //$oldmsg[] = $content;
        //++$tot;
            echo $content;
        }
    
    </body>
</html>
Copy after login

永久链接:

转载随意!带上文章地址吧。

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve PHP Warning: fopen(): failed to open stream: No such file or directory How to solve PHP Warning: fopen(): failed to open stream: No such file or directory Aug 19, 2023 am 10:44 AM

How to solve PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory In the process of using PHP development, we often encounter some file operation problems, one of which is "PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectory"

How to solve PHP Warning: fopen(): SSL operation failed in file.php on line X How to solve PHP Warning: fopen(): SSL operation failed in file.php on line X Aug 25, 2023 am 09:22 AM

How to solve PHPWarning:fopen():SSLoperationfailedinfile.phponlineX In PHP programming, we often use the fopen function to open files or URLs and perform related operations. However, when using the fopen function, sometimes you will encounter something similar to Warning:fopen():SSLoperationfailedinfile.p

How to solve PHP Warning: fopen(): failed to open stream: Permission denied How to solve PHP Warning: fopen(): failed to open stream: Permission denied Aug 20, 2023 pm 01:45 PM

How to solve PHPWarning:fopen():failedtoopenstream:Permissiondenied In the process of developing PHP programs, we often encounter some error messages, such as PHPWarning:fopen():failedtoopenstream:Permissiondenied. This error is usually due to incorrect file or directory permissions

Usage of fopen function in Matlab Usage of fopen function in Matlab Nov 28, 2023 am 11:03 AM

In Matlab, the fopen function is used to open a file and return the file identifier for subsequent reading or writing operations on the file. Select the appropriate permission options to open the file as needed, and promptly close the file when the operation is complete. It should be noted that after opening a file, you need to ensure that the file is closed in time when it is no longer needed to release system resources. In addition, if the file opening fails or an operation error occurs, the error handling mechanism can be used to handle it accordingly.

How to use fopen, fwrite and fclose in php for file operations? How to use fopen, fwrite and fclose in php for file operations? Jun 01, 2023 am 08:46 AM

In PHP development, file operations are very common. Under normal circumstances, we need to perform file reading, writing, deletion and other operations. Among them, the fopen function and fread function can be used to read the file, and the fopen function, fwrite function and fclose function can be used to write the file. This article will introduce how PHP uses fopen, fwrite and fclose to perform file operations. 1. fopen function The fopen function is used to open files. Its syntax is as follows: r

In C language, use the fopen() function to open an existing file in write mode In C language, use the fopen() function to open an existing file in write mode Aug 27, 2023 pm 10:33 PM

The fopen() method in C is used to open the specified file. Let's take an example to understand the problem syntax FILE*fopen(filename,mode). The following are valid modes for using fopen() to open files: 'r', 'w', 'a', 'r+', 'w+', ' a+'. For more information, please visit the C library function-fopen()

如何解决PHP Warning: fopen(): failed to open stream: No such file or directory in file.php on line X 如何解决PHP Warning: fopen(): failed to open stream: No such file or directory in file.php on line X Aug 26, 2023 pm 12:46 PM

How to solve PHPWarning:fopen():failedtoopenstream:Nosuchfileordirectoryinfile.phponlineX When developing and running PHP programs, we sometimes encounter PHPWarning:fopen():failedtoopenstream:Nosuchfileor

How to set textarea read-only How to set textarea read-only Sep 28, 2023 am 11:17 AM

You can use the readonly attribute, disabled and readwrite attributes to set the textarea read-only. Detailed introduction: 1. readonly attribute, the value of the readonly attribute is readonly; 2. disabled attribute, the content of the <textarea> element cannot be changed, because the value of the disabled attribute is disabled; 3. readwrite attribute, the content of the <textarea> element can Changes and more.

See all articles