This is my php code, and i am trying to create a chat
<!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>
I know that php isn't the way to go, but I want to have some fun, and it seems to be working out. Also, I want to ask how do you let the chat let real time. I created a document called chat.txt and maybe i can detect when it is changed, and then reload. There are 2 problems to this method. 1. after each reload the message you previously typed is typed again 2.I don't know how to detect change, and have not found any way to do this does anyone have solutions to this? (other methods would be fine) P.S. I'm horrible at php