1 parent
e28a164a5c
commit
756d2a98b2
3 files changed
+136
-126
No files matched your search
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
if (!isset($_GET['user'])) {
|
||||
http_response_code(400);
|
||||
exit("Missing user");
|
||||
}
|
||||
|
||||
$user = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['user']);
|
||||
header("Content-Type: text/event-stream");
|
||||
header("Cache-Control: no-cache");
|
||||
header("Connection: keep-alive");
|
||||
|
||||
$tmp_file = sys_get_temp_dir() . "/relay_chat_{$user}.txt";
|
||||
|
||||
if (!file_exists($tmp_file)) {
|
||||
file_put_contents($tmp_file, '');
|
||||
}
|
||||
|
||||
$last_modif = 0;
|
||||
|
||||
while (true) {
|
||||
clearstatcache();
|
||||
$current_modif = filemtime($tmp_file);
|
||||
|
||||
if ($current_modif > $last_modif) {
|
||||
$last_modif = $current_modif;
|
||||
$data = file_get_contents($tmp_file);
|
||||
echo "data: " . trim($data) . "\n\n";
|
||||
ob_flush();
|
||||
flush();
|
||||
}
|
||||
|
||||
sleep(1);
|
||||
}
|
||||
?>
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
if (isset($_POST['mensagem']) && isset($_GET['user'])) {
|
||||
$mensagem = trim($_POST['mensagem']);
|
||||
$user = preg_replace('/[^a-zA-Z0-9_-]/', '', $_GET['user']); // sanitiza o nome do usuário
|
||||
|
||||
if ($mensagem !== '') {
|
||||
$tmp_file = sys_get_temp_dir() . "/relay_chat_{$user}.txt";
|
||||
file_put_contents($tmp_file, $mensagem);
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in new issue
Block a user