【发布时间】:2020-06-08 04:22:27
【问题描述】:
这是我的 php 代码,我正在尝试创建一个聊天
<!DOCTYPE html>
<html>
<body>
<html>
<?php
session_start();
$userinput = $_GET["name"];
if (empty($userinput)){
} else {
$myfile = fopen("chat.txt", "a");
fwrite($myfile, $userinput);
fwrite($myfile, "<br>
");
}
$chatfile = fopen("chat.txt", "r");
echo fread($chatfile,filesize("chat.txt"));
echo $chatfile;
?>
</body>
</html>
<form method="get" id="myForm" action="">
<input type="text" name="name"
placeholder="type in your comment" autofocus>
<input type="submit">
</form>
<script>
</script>
</body>
</html>
我知道 php 不是要走的路,但我想找点乐子,而且它似乎正在奏效。 另外,我想问一下你如何让聊天实时。 我创建了一个名为 chat.txt 的文档,也许我可以检测到它何时更改,然后重新加载。 这种方法有两个问题。 1. 每次重新加载后,您之前输入的消息会再次输入 2.我不知道如何检测变化,也没有找到任何方法来做到这一点 有人对此有解决方案吗? (其他方法也可以) 附:我对php很糟糕
【问题讨论】: