-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwrite.php
28 lines (28 loc) · 906 Bytes
/
write.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
<?php
session_start();
$sid=$_SESSION['usr'];
$message = $_REQUEST["message"];
$chatLog = file_get_contents('chatLog.txt');
$chatLog = $chatLog.$sid.":".$message."\n"."</br>";
file_put_contents('chatLog.txt', $chatLog);
$chatString=$message;
$chatString= preg_replace("/[^a-zA-Z]/", "", $chatString);
$chatString= strtolower($chatString);
$mng = new MongoDB\Driver\Manager("mongodb://localhost:27017");
$lastMes = file_get_contents('chatLog.txt');
$lastMes= preg_replace("</br>", "", $lastMes);
$arr = explode("\n",$lastMes);
for($i=0;$i<sizeof($arr)-1;$i++)
{
if(( strpos( $arr[$i], $sid ) == false ))
{
$lastMes=$arr[$i];
}
}
$lastMes= preg_replace("/[^a-zA-Z]/", "", $lastMes);
$lastMes= strtolower($lastMes);
$bulk = new MongoDB\Driver\BulkWrite;
$doc = ['_id' => new MongoDB\BSON\ObjectID, $lastMes=> $message];
$bulk->insert($doc);
$mng->executeBulkWrite("mark1.".$sid, $bulk);
?>