-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit_session.php
More file actions
70 lines (63 loc) · 1.97 KB
/
init_session.php
File metadata and controls
70 lines (63 loc) · 1.97 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
/**
* Session-Initialisierung
* Dateipfad: /image-compressor/init_session.php
*
* Diese Datei wird am Anfang jeder Seite eingebunden um sicherzustellen,
* dass alte Sessions bereinigt werden
*/
// Starte Session falls noch nicht aktiv
if (session_status() === PHP_SESSION_NONE) {
session_start();
}
/**
* Prüft ob eine neue Session gestartet werden soll
*/
function checkAndResetSession() {
// Prüfe ob Reset angefordert wurde
if (isset($_GET['reset']) && $_GET['reset'] === '1') {
resetImageSession();
header('Location: index.php');
exit;
}
// Prüfe ob Session zu alt ist (älter als 1 Stunde)
if (isset($_SESSION['session_start_time'])) {
$sessionAge = time() - $_SESSION['session_start_time'];
if ($sessionAge > 3600) { // 1 Stunde
resetImageSession();
}
} else {
$_SESSION['session_start_time'] = time();
}
}
/**
* Setzt die Bild-Session zurück
*/
function resetImageSession() {
// Lösche alle hochgeladenen Dateien
if (isset($_SESSION['uploaded_files'])) {
foreach ($_SESSION['uploaded_files'] as $file) {
if (file_exists($file['path'])) {
unlink($file['path']);
}
}
}
// Lösche alle verarbeiteten Dateien
if (isset($_SESSION['processed_files'])) {
foreach ($_SESSION['processed_files'] as $file) {
if (file_exists($file['processed_path'])) {
unlink($file['processed_path']);
}
if (file_exists($file['thumbnail_path'])) {
unlink($file['thumbnail_path']);
}
}
}
// Setze Session-Variablen zurück
unset($_SESSION['uploaded_files']);
unset($_SESSION['processed_files']);
unset($_SESSION['upload_session_id']);
$_SESSION['session_start_time'] = time();
}
// Führe Session-Check aus
checkAndResetSession();