-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.php
86 lines (82 loc) · 2.58 KB
/
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
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
<?php
session_start();
?>
<html>
<?php
if(!isset($_COOKIE['me']))
{
die("<div style='padding:50px 0 50px 0;text-align: center;font-family: ubuntu;font-size: 18px;color:#777;background-color:#f7f7f7;border:1px solid #d0d0d0;'>please login.<a href='shoutbox.php' style='color:#555;text-decoration:none;'>click to go back</a></div>");
}
if(strcmp($_COOKIE['me'],$_GET['me']))
{
die("<div style='padding:50px 0 50px 0;text-align: center;font-family: ubuntu;font-size: 18px;color:#777;background-color:#f7f7f7;border:1px solid #d0d0d0;'>nice try mate. sorry to dissapoint you.<a href='shoutbox.php' style='color:#555;text-decoration:none;'>click to go back</a></div>");
}
if(!isset($_REQUEST['you']))
{
die("<div style='padding:50px 0 50px 0;text-align: center;font-family: ubuntu;font-size: 18px;color:#777;background-color:#f7f7f7;border:1px solid #d0d0d0;'>what are you doing here?<a href='shoutbox.php' style='color:#555;text-decoration:none;'>click to go back</a></div>");
}
?>
<head>
<script src="scripts/jquery.min.js"></script>
<script type='text/javascript'>
var me="<?php echo $_REQUEST['me'];?>";
var you="<?php echo $_REQUEST['you'];?>";
var id;
var source=new EventSource("stream.php?me="+me+"&you="+you);
source.onmessage=function(event)
{
var msg=$.parseJSON(event.data);
if(msg.message!='error')
{ if(msg.id!=id)
{
id=msg.id;
$("#wall").append("<b>"+you+"</b>: "+msg.message+"<br/>");
}
}
};
$(window).unload(function()
{
$.ajax({
url:'clear.php',
type:'POST',
data:{'me':me,'you':you}
});
});
$(document).ready(function()
{
$('#input').keyup(function(event)
{
if(event.keyCode==13)
{
$('#button').click();
}
});
$('#button').click(function()
{
var message=$('#input').val();
$('#wall').append("<b>"+me+"</b>: "+message+"<br/>");
$('#input').val(' ');
$.ajax({
url:'store.php',
data:{'type':'put','me':me,'you':you,'message':message},
type:'POST',
success:function()
{
}
});
});
});
</script>
</head>
<body>
<input type='text' style='float:left;width:300px;height:42px;border:1px solid #d0d0d0;color:#666;'placeholder='write something' id='input'/><span style='float:left;width:100px;padding:10px;background-color:#f1f1f1;text-align:center;color:#555;border:1px solid #d0d0d0;' id='button' >submit</span>
<?php
if(isset($_COOKIE['me']))
{
echo "<a href='unset.php?me=".$_COOKIE['me']."' style='float:right;padding:10px;text-align:center;color:#555;font-size:20px;'>logout</a>";
}
?>
<div id='wall' style='float:left;clear:both;width:100%;padding:10px;height:auto;min-height:200px;background-color:#f7f7f7;border:1px solid #f1f1f1;'>
</div>
</body>
</html>