-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathactivesession.php
More file actions
27 lines (27 loc) · 882 Bytes
/
Copy pathactivesession.php
File metadata and controls
27 lines (27 loc) · 882 Bytes
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
<?php
$timeout = 100; // 5 minutes
$time = time();
$ip = $_SERVER["REMOTE_ADDR"];
$file = "users.txt";
$arr = file($file);
$users = 0;
for ($i = 0; $i < count($arr); $i++){
if ($time - intval(substr($arr[$i], strpos($arr[$i], " ") + 4)) > $timeout){
unset($arr[$i]);
$arr = array_values($arr);
file_put_contents($file, implode($arr)); // 'Glue' array elements into string
}
$users++;
}
echo $users;
// Only add entry if user isn't already there, otherwise just edit timestamp
for ($i = 0; $i < count($arr); $i++){
if (substr($arr[$i], 0, strlen($ip)) == $ip){
$arr[$i] = substr($arr[$i], 0, strlen($ip))." ".$time."\n";
$arr = array_values($arr);
file_put_contents($file, implode($arr)); // 'Glue' array elements into string
exit;
}
}
file_put_contents($file, $ip." ".$time."\n", FILE_APPEND);
?>