-
Notifications
You must be signed in to change notification settings - Fork 33
/
htmlchat.php
133 lines (115 loc) · 3.12 KB
/
htmlchat.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
<HEAD>
<SCRIPT>
function getContent(url, target) {
document.getElementById(target).innerHTML = ' Fetching data...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != undefined) {
req.onreadystatechange = function() {getContentDone(url, target);};
req.open("GET", url, true);
req.send("");
}
}
function getContentDone(url, target) {
if (req.readyState == 4) { // only if req is "loaded"
if (req.status == 200) { // only if "OK"
document.getElementById(target).innerHTML = req.responseText;
document.getElementById(target).scrollTop = document.getElementById(target).scrollHeight;
} else {
document.getElementById(target).innerHTML=" Chat History:\n"+ req.status + "\n" +req.statusText;
}
}
}
function load(name, div) {
getContent(name,div);
return false;
}
</SCRIPT>
<title><?=$n?> Text Chat</title>
</HEAD>
<BODY>
<?php
$room = $_GET['n'];
if (!$room) $room = $_POST['n'];
//do not allow access to other folders
if ( strstr($room,"/") || strstr($room,"..") )
{
echo "Access denied.";
exit;
}
$name = $_POST['name'];
$message = $_POST['message'];
//security
include_once("incsan.php");
sanV($room);
sanV($name);
sanV($message, 0);
$day=date("y-M-j",time());
$chatfile = "uploads/$room/Log$day.html";
?>
<form action="htmlchat.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
Name:
<input name="name" type="text" id="name" size="16" maxlength="32" value="<?php echo $name ?>" />
Message:
<input name="message" type="text" id="message" size="32" />
<input type="hidden" name="n" id="n" value="<?php echo $room ?>" />
<input type="submit" name="button" id="button" value="Send" />
</form>
<?php
if ($name && $message && $room!="null")
{
$dir="uploads";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0755);
$dir.="/$room";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0755);
$show = "<font color=\"#337733\"><B>$name</B>: $message</font>";
$dfile = fopen($chatfile,"a");
fputs($dfile, $show . "<BR>");
fclose($dfile);
$dir.="/external";
if (!file_exists($dir)) mkdir($dir);
@chmod($dir, 0755);
$dfile = fopen("uploads/$room/external/$day.html","a");
fputs($dfile, "\"" . time(). "\",\"" . $show . "\";;\r\n");
fclose($dfile);
}
//if (file_exists($chatfile)) echo implode('', file($chatfile));
?>
<style type="text/css">
<!--
#chathistory {
overflow: auto;
height:150px;
width:100%;
background-color: #E3E3E3;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
}
input {
border: 1px solid #BBB;
color: #666;
font-weight: normal;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
}
body {
font-family: Arial, Helvetica, sans-serif;
font-size: 15px;
color: #666;
background-color: #eee;
}
-->
</style>
<div id="chathistory" name="chathistory">
Loading chat history...
</div>
<script>
load('<?php echo $chatfile?>', 'chathistory');
setInterval( "load('<?php echo $chatfile?>', 'chathistory')", 6000);
</script>
</BODY>