1
|
|
|
<?php |
|
|
|
|
2
|
|
|
/*************************************************************************** |
3
|
|
|
* For license information see doc/license.txt |
4
|
|
|
* |
5
|
|
|
* Unicode Reminder メモ |
6
|
|
|
* |
7
|
|
|
* Cookie handling |
8
|
|
|
***************************************************************************/ |
9
|
|
|
|
10
|
|
|
$cookie = new cookie(); |
11
|
|
|
|
12
|
|
|
class cookie |
|
|
|
|
13
|
|
|
{ |
14
|
|
|
public $changed = false; |
15
|
|
|
public $values = array(); |
16
|
|
|
|
17
|
|
View Code Duplication |
public function __construct() |
|
|
|
|
18
|
|
|
{ |
19
|
|
|
global $opt; |
20
|
|
|
|
21
|
|
|
if (isset($_COOKIE[$opt['cookie']['name'] . 'data'])) { |
22
|
|
|
//get the cookievars-array |
23
|
|
|
$decoded = base64_decode($_COOKIE[$opt['cookie']['name'] . 'data']); |
24
|
|
|
|
25
|
|
|
if ($decoded !== false) { |
26
|
|
|
$this->values = @unserialize($decoded); |
|
|
|
|
27
|
|
|
if (!is_array($this->values)) { |
28
|
|
|
$this->values = array(); |
29
|
|
|
} |
30
|
|
|
} else { |
31
|
|
|
$this->values = array(); |
32
|
|
|
} |
33
|
|
|
} |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
public function set($name, $value) |
37
|
|
|
{ |
38
|
|
|
if (!isset($this->values[$name]) || $this->values[$name] != $value) { |
39
|
|
|
$this->values[$name] = $value; |
40
|
|
|
$this->changed = true; |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
public function get($name) |
45
|
|
|
{ |
46
|
|
|
return isset($this->values[$name]) ? $this->values[$name] : ''; |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function is_set($name) |
50
|
|
|
{ |
51
|
|
|
return isset($this->values[$name]); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
View Code Duplication |
public function un_set($name) |
|
|
|
|
55
|
|
|
{ |
56
|
|
|
if (isset($this->values[$name])) { |
57
|
|
|
unset($this->values[$name]); |
58
|
|
|
$this->changed = true; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
public function header() |
63
|
|
|
{ |
64
|
|
|
global $opt; |
65
|
|
|
|
66
|
|
|
if ($this->changed == true) { |
|
|
|
|
67
|
|
|
if (count($this->values) == 0) { |
68
|
|
|
setcookie( |
69
|
|
|
$opt['cookie']['name'] . 'data', |
70
|
|
|
false, |
71
|
|
|
time() + 31536000, |
72
|
|
|
$opt['cookie']['path'], |
73
|
|
|
$opt['cookie']['domain'], |
74
|
|
|
0 |
75
|
|
|
); |
76
|
|
|
} else { |
77
|
|
|
setcookie( |
78
|
|
|
$opt['cookie']['name'] . 'data', |
79
|
|
|
base64_encode(serialize($this->values)), |
80
|
|
|
time() + 31536000, |
81
|
|
|
$opt['cookie']['path'], |
82
|
|
|
$opt['cookie']['domain'], |
83
|
|
|
0 |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function debug() |
90
|
|
|
{ |
91
|
|
|
print_r($this->values); |
92
|
|
|
exit; |
|
|
|
|
93
|
|
|
} |
94
|
|
|
} |
95
|
|
|
|
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.