-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_new.php
More file actions
38 lines (27 loc) · 1.07 KB
/
create_new.php
File metadata and controls
38 lines (27 loc) · 1.07 KB
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
<?php
session_start();
$username=$_SESSION['username'];
$newSessionName = $_POST['newSession']; // Using timestamp for uniqueness
// Remove all special characters except -!@#$%&
$newSessionName = preg_replace('/[^a-zA-Z0-9\s\-!@]/', '', $newSessionName);
$lastChar = substr($newSessionName, -1);
if ($lastChar === ' ') {
$newSessionName = substr($newSessionName, 0, -1);
}
// Create a new session
$info = '[' . $username . '-' . date("Y-m-d H.i.s") . ']
';
$sessionFolder = "sessions/";
$chatFilePath = $sessionFolder . $newSessionName . "_session.txt";
// Check if the file already exists
$counter = 1;
while (file_exists($chatFilePath)) {
$newSessionName = $_POST['newSession'] . " ($counter)";
$chatFilePath = $sessionFolder . $newSessionName . "_session.txt";
$counter++;
}
// Create the new session file
file_put_contents($chatFilePath, $info); // Start with an empty file
include("lib/logfile.php");
$_SESSION['selected_session'] = $newSessionName;
header("Location: chat.php?session=$newSessionName");