-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHistory.php
More file actions
40 lines (29 loc) · 944 Bytes
/
History.php
File metadata and controls
40 lines (29 loc) · 944 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
28
29
30
31
32
33
34
35
36
37
38
39
40
<?php
class History {
private $user_history;
public function __construct() {
session_start();
if(!isset($_SESSION['history'])) {
settype($_SESSION['history'], 'array');
}
array_unshift($_SESSION['history'], $_SERVER['PHP_SELF']);
if(count($_SESSION['history'])>5) {
array_pop($_SESSION['history']);
}
$user_history = serialize($_SESSION['history']);
if(!isset($_COOKIE['history'])) {
setcookie('history',$user_history,time()+60*60*24*30);
echo 'cookie created';
}else {
$_COOKIE['history'] = $user_history;
}
}
public function render() {
if (!isset($_SESSION['history']) && isset($_COOKIE['history'])) {
$user_history = unserialize($_COOKIE['history']);
foreach($user_history as $val) {
echo $val;
}
}
}
}