-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathchat.php
27 lines (23 loc) · 824 Bytes
/
chat.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
<?php
session_start();
if(isset($_POST['ajaxsend']) && $_POST['ajaxsend']==true){
// Code to save and send chat
$chat = fopen("chatdata.txt", "a");
$data="<b>".$_SESSION['username'].':</b> '.$_POST['chat']."<br>";
fwrite($chat,$data);
fclose($chat);
$chat = fopen("chatdata.txt", "r");
echo fread($chat,filesize("chatdata.txt"));
fclose($chat);
} else if(isset($_POST['ajaxget']) && $_POST['ajaxget']==true){
// Code to send chat history to the user
$chat = fopen("chatdata.txt", "r");
echo fread($chat,filesize("chatdata.txt"));
fclose($chat);
} else if(isset($_POST['ajaxclear']) && $_POST['ajaxclear']==true){
// Code to clear chat history
$chat = fopen("chatdata.txt", "w");
$data="<b>".$_SESSION['username'].'</b> cleared chat<br>';
fwrite($chat,$data);
fclose($chat);
}