-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_session.php
More file actions
46 lines (38 loc) · 1.28 KB
/
delete_session.php
File metadata and controls
46 lines (38 loc) · 1.28 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
38
39
40
41
42
43
44
45
46
<?php
// Start or resume the session
session_start();
// Assuming you have a function to check if the user is logged in
if (!isset($_SESSION['username'])) {
// Redirect to the login page if the user is not logged in
header("Location: login.php");
exit();
}
// Check if POST data containing the filename is received
if (isset($_POST['filename'])) {
$filename = $_POST['filename'];
// Perform any necessary validation on the filename
// Check if the file has less than 2 lines of content
$lines = file($filename, FILE_IGNORE_NEW_LINES | FILE_SKIP_EMPTY_LINES);
$lineCount = count($lines);
if ($lineCount < 2) {
// Delete the file (adjust the path as needed)
if (file_exists($filename)) {
unlink($filename);
// Log out all sessions
// session_destroy();
// Redirect to the login page after logout
header("Location: index.php");
exit();
} else {
// Handle file not found or other error
echo "Error: File $filename not found or could not be deleted.";
}
} else {
header("Location: chat.php");
exit();
}
} else {
// Handle missing filename in POST data
echo "Error: Filename not provided.";
}
?>