1 | <?php |
||
23 | class SimpleCookie { |
||
24 | var $_host; |
||
25 | var $_name; |
||
26 | var $_value; |
||
27 | var $_path; |
||
28 | var $_expiry; |
||
29 | var $_is_secure; |
||
30 | |||
31 | /** |
||
32 | * Constructor. Sets the stored values. |
||
33 | * @param string $name Cookie key. |
||
34 | * @param string $value Value of cookie. |
||
35 | * @param string $path Cookie path if not host wide. |
||
36 | * @param string $expiry Expiry date as string. |
||
37 | * @param boolean $is_secure Currently ignored. |
||
38 | */ |
||
39 | function SimpleCookie($name, $value = false, $path = false, $expiry = false, $is_secure = false) { |
||
40 | $this->_host = false; |
||
41 | $this->_name = $name; |
||
42 | $this->_value = $value; |
||
43 | $this->_path = ($path ? $this->_fixPath($path) : "/"); |
||
44 | $this->_expiry = false; |
||
45 | if (is_string($expiry)) { |
||
46 | $this->_expiry = strtotime($expiry); |
||
47 | } elseif (is_integer($expiry)) { |
||
48 | $this->_expiry = $expiry; |
||
49 | } |
||
50 | $this->_is_secure = $is_secure; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Sets the host. The cookie rules determine |
||
55 | * that the first two parts are taken for |
||
56 | * certain TLDs and three for others. If the |
||
57 | * new host does not match these rules then the |
||
58 | * call will fail. |
||
59 | * @param string $host New hostname. |
||
60 | * @return boolean True if hostname is valid. |
||
61 | * @access public |
||
62 | */ |
||
63 | function setHost($host) { |
||
70 | |||
71 | /** |
||
72 | * Accessor for the truncated host to which this |
||
73 | * cookie applies. |
||
74 | * @return string Truncated hostname. |
||
75 | * @access public |
||
76 | */ |
||
77 | function getHost() { |
||
80 | |||
81 | /** |
||
82 | * Test for a cookie being valid for a host name. |
||
83 | * @param string $host Host to test against. |
||
84 | * @return boolean True if the cookie would be valid |
||
85 | * here. |
||
86 | */ |
||
87 | function isValidHost($host) { |
||
90 | |||
91 | /** |
||
92 | * Extracts just the domain part that determines a |
||
93 | * cookie's host validity. |
||
94 | * @param string $host Host name to truncate. |
||
95 | * @return string Domain or false on a bad host. |
||
96 | * @access private |
||
97 | */ |
||
98 | function _truncateHost($host) { |
||
107 | |||
108 | /** |
||
109 | * Accessor for name. |
||
110 | * @return string Cookie key. |
||
111 | * @access public |
||
112 | */ |
||
113 | function getName() { |
||
116 | |||
117 | /** |
||
118 | * Accessor for value. A deleted cookie will |
||
119 | * have an empty string for this. |
||
120 | * @return string Cookie value. |
||
121 | * @access public |
||
122 | */ |
||
123 | function getValue() { |
||
126 | |||
127 | /** |
||
128 | * Accessor for path. |
||
129 | * @return string Valid cookie path. |
||
130 | * @access public |
||
131 | */ |
||
132 | function getPath() { |
||
135 | |||
136 | /** |
||
137 | * Tests a path to see if the cookie applies |
||
138 | * there. The test path must be longer or |
||
139 | * equal to the cookie path. |
||
140 | * @param string $path Path to test against. |
||
141 | * @return boolean True if cookie valid here. |
||
142 | * @access public |
||
143 | */ |
||
144 | function isValidPath($path) { |
||
150 | |||
151 | /** |
||
152 | * Accessor for expiry. |
||
153 | * @return string Expiry string. |
||
154 | * @access public |
||
155 | */ |
||
156 | function getExpiry() { |
||
162 | |||
163 | /** |
||
164 | * Test to see if cookie is expired against |
||
165 | * the cookie format time or timestamp. |
||
166 | * Will give true for a session cookie. |
||
167 | * @param integer/string $now Time to test against. Result |
||
168 | * will be false if this time |
||
169 | * is later than the cookie expiry. |
||
170 | * Can be either a timestamp integer |
||
171 | * or a cookie format date. |
||
172 | * @access public |
||
173 | */ |
||
174 | function isExpired($now) { |
||
183 | |||
184 | /** |
||
185 | * Ages the cookie by the specified number of |
||
186 | * seconds. |
||
187 | * @param integer $interval In seconds. |
||
188 | * @public |
||
189 | */ |
||
190 | function agePrematurely($interval) { |
||
195 | |||
196 | /** |
||
197 | * Accessor for the secure flag. |
||
198 | * @return boolean True if cookie needs SSL. |
||
199 | * @access public |
||
200 | */ |
||
201 | function isSecure() { |
||
204 | |||
205 | /** |
||
206 | * Adds a trailing and leading slash to the path |
||
207 | * if missing. |
||
208 | * @param string $path Path to fix. |
||
209 | * @access private |
||
210 | */ |
||
211 | function _fixPath($path) { |
||
220 | } |
||
221 | |||
381 |