Subversion Repositories eFlore/Applications.cel

Rev

Rev 418 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 418 Rev 3473
1
<?php
1
<?php
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
2
/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
3
 
3
 
4
/**
4
/**
5
 * HTTP::Header
5
 * HTTP::Header
6
 * 
6
 * 
7
 * PHP versions 4 and 5
7
 * PHP versions 4 and 5
8
 *
8
 *
9
 * @category    HTTP
9
 * @category    HTTP
10
 * @package     HTTP_Header
10
 * @package     HTTP_Header
11
 * @author      Wolfram Kriesing <wk@visionp.de>
11
 * @author      Wolfram Kriesing <wk@visionp.de>
12
 * @author      Davey Shafik <davey@php.net>
12
 * @author      Davey Shafik <davey@php.net>
13
 * @author      Michael Wallner <mike@php.net>
13
 * @author      Michael Wallner <mike@php.net>
14
 * @copyright   2003-2005 The Authors
14
 * @copyright   2003-2005 The Authors
15
 * @license     BSD, revised
15
 * @license     BSD, revised
16
 * @version     CVS: $Id$
16
 * @version     CVS: $Id$
17
 * @link        http://pear.php.net/package/HTTP_Header
17
 * @link        http://pear.php.net/package/HTTP_Header
18
 */
18
 */
19
 
19
 
20
/**
20
/**
21
 * Requires HTTP
21
 * Requires HTTP
22
 */
22
 */
23
require_once 'HTTP.php';
23
require_once 'HTTP.php';
24
 
24
 
25
/**#@+
25
/**#@+
26
 * Information Codes
26
 * Information Codes
27
 */
27
 */
28
define('HTTP_HEADER_STATUS_100', '100 Continue');
28
define('HTTP_HEADER_STATUS_100', '100 Continue');
29
define('HTTP_HEADER_STATUS_101', '101 Switching Protocols');
29
define('HTTP_HEADER_STATUS_101', '101 Switching Protocols');
30
define('HTTP_HEADER_STATUS_102', '102 Processing');
30
define('HTTP_HEADER_STATUS_102', '102 Processing');
31
define('HTTP_HEADER_STATUS_INFORMATIONAL',1);
31
define('HTTP_HEADER_STATUS_INFORMATIONAL',1);
32
/**#@-*/
32
/**#@-*/
33
 
33
 
34
/**#+
34
/**#+
35
 * Success Codes
35
 * Success Codes
36
 */
36
 */
37
define('HTTP_HEADER_STATUS_200', '200 OK');
37
define('HTTP_HEADER_STATUS_200', '200 OK');
38
define('HTTP_HEADER_STATUS_201', '201 Created');
38
define('HTTP_HEADER_STATUS_201', '201 Created');
39
define('HTTP_HEADER_STATUS_202', '202 Accepted');
39
define('HTTP_HEADER_STATUS_202', '202 Accepted');
40
define('HTTP_HEADER_STATUS_203', '203 Non-Authoritative Information');
40
define('HTTP_HEADER_STATUS_203', '203 Non-Authoritative Information');
41
define('HTTP_HEADER_STATUS_204', '204 No Content');
41
define('HTTP_HEADER_STATUS_204', '204 No Content');
42
define('HTTP_HEADER_STATUS_205', '205 Reset Content');
42
define('HTTP_HEADER_STATUS_205', '205 Reset Content');
43
define('HTTP_HEADER_STATUS_206', '206 Partial Content');
43
define('HTTP_HEADER_STATUS_206', '206 Partial Content');
44
define('HTTP_HEADER_STATUS_207', '207 Multi-Status');
44
define('HTTP_HEADER_STATUS_207', '207 Multi-Status');
45
define('HTTP_HEADER_STATUS_SUCCESSFUL',2);
45
define('HTTP_HEADER_STATUS_SUCCESSFUL',2);
46
/**#@-*/
46
/**#@-*/
47
 
47
 
48
/**#@+
48
/**#@+
49
 * Redirection Codes
49
 * Redirection Codes
50
 */
50
 */
51
define('HTTP_HEADER_STATUS_300', '300 Multiple Choices');
51
define('HTTP_HEADER_STATUS_300', '300 Multiple Choices');
52
define('HTTP_HEADER_STATUS_301', '301 Moved Permanently');
52
define('HTTP_HEADER_STATUS_301', '301 Moved Permanently');
53
define('HTTP_HEADER_STATUS_302', '302 Found');
53
define('HTTP_HEADER_STATUS_302', '302 Found');
54
define('HTTP_HEADER_STATUS_303', '303 See Other');
54
define('HTTP_HEADER_STATUS_303', '303 See Other');
55
define('HTTP_HEADER_STATUS_304', '304 Not Modified');
55
define('HTTP_HEADER_STATUS_304', '304 Not Modified');
56
define('HTTP_HEADER_STATUS_305', '305 Use Proxy');
56
define('HTTP_HEADER_STATUS_305', '305 Use Proxy');
57
define('HTTP_HEADER_STATUS_306', '306 (Unused)');
57
define('HTTP_HEADER_STATUS_306', '306 (Unused)');
58
define('HTTP_HEADER_STATUS_307', '307 Temporary Redirect');
58
define('HTTP_HEADER_STATUS_307', '307 Temporary Redirect');
59
define('HTTP_HEADER_STATUS_REDIRECT',3);
59
define('HTTP_HEADER_STATUS_REDIRECT',3);
60
/**#@-*/
60
/**#@-*/
61
 
61
 
62
/**#@+
62
/**#@+
63
 * Error Codes
63
 * Error Codes
64
 */
64
 */
65
define('HTTP_HEADER_STATUS_400', '400 Bad Request');
65
define('HTTP_HEADER_STATUS_400', '400 Bad Request');
66
define('HTTP_HEADER_STATUS_401', '401 Unauthorized');
66
define('HTTP_HEADER_STATUS_401', '401 Unauthorized');
67
define('HTTP_HEADER_STATUS_402', '402 Payment Granted');
67
define('HTTP_HEADER_STATUS_402', '402 Payment Granted');
68
define('HTTP_HEADER_STATUS_403', '403 Forbidden');
68
define('HTTP_HEADER_STATUS_403', '403 Forbidden');
69
define('HTTP_HEADER_STATUS_404', '404 File Not Found');
69
define('HTTP_HEADER_STATUS_404', '404 File Not Found');
70
define('HTTP_HEADER_STATUS_405', '405 Method Not Allowed');
70
define('HTTP_HEADER_STATUS_405', '405 Method Not Allowed');
71
define('HTTP_HEADER_STATUS_406', '406 Not Acceptable');
71
define('HTTP_HEADER_STATUS_406', '406 Not Acceptable');
72
define('HTTP_HEADER_STATUS_407', '407 Proxy Authentication Required');
72
define('HTTP_HEADER_STATUS_407', '407 Proxy Authentication Required');
73
define('HTTP_HEADER_STATUS_408', '408 Request Time-out');
73
define('HTTP_HEADER_STATUS_408', '408 Request Time-out');
74
define('HTTP_HEADER_STATUS_409', '409 Conflict');
74
define('HTTP_HEADER_STATUS_409', '409 Conflict');
75
define('HTTP_HEADER_STATUS_410', '410 Gone');
75
define('HTTP_HEADER_STATUS_410', '410 Gone');
76
define('HTTP_HEADER_STATUS_411', '411 Length Required');
76
define('HTTP_HEADER_STATUS_411', '411 Length Required');
77
define('HTTP_HEADER_STATUS_412', '412 Precondition Failed');
77
define('HTTP_HEADER_STATUS_412', '412 Precondition Failed');
78
define('HTTP_HEADER_STATUS_413', '413 Request Entity Too Large');
78
define('HTTP_HEADER_STATUS_413', '413 Request Entity Too Large');
79
define('HTTP_HEADER_STATUS_414', '414 Request-URI Too Large');
79
define('HTTP_HEADER_STATUS_414', '414 Request-URI Too Large');
80
define('HTTP_HEADER_STATUS_415', '415 Unsupported Media Type');
80
define('HTTP_HEADER_STATUS_415', '415 Unsupported Media Type');
81
define('HTTP_HEADER_STATUS_416', '416 Requested range not satisfiable');
81
define('HTTP_HEADER_STATUS_416', '416 Requested range not satisfiable');
82
define('HTTP_HEADER_STATUS_417', '417 Expectation Failed');
82
define('HTTP_HEADER_STATUS_417', '417 Expectation Failed');
83
define('HTTP_HEADER_STATUS_422', '422 Unprocessable Entity');
83
define('HTTP_HEADER_STATUS_422', '422 Unprocessable Entity');
84
define('HTTP_HEADER_STATUS_423', '423 Locked');
84
define('HTTP_HEADER_STATUS_423', '423 Locked');
85
define('HTTP_HEADER_STATUS_424', '424 Failed Dependency');
85
define('HTTP_HEADER_STATUS_424', '424 Failed Dependency');
86
define('HTTP_HEADER_STATUS_CLIENT_ERROR',4);
86
define('HTTP_HEADER_STATUS_CLIENT_ERROR',4);
87
/**#@-*/
87
/**#@-*/
88
 
88
 
89
/**#@+
89
/**#@+
90
 * Server Errors
90
 * Server Errors
91
 */
91
 */
92
define('HTTP_HEADER_STATUS_500', '500 Internal Server Error');
92
define('HTTP_HEADER_STATUS_500', '500 Internal Server Error');
93
define('HTTP_HEADER_STATUS_501', '501 Not Implemented');
93
define('HTTP_HEADER_STATUS_501', '501 Not Implemented');
94
define('HTTP_HEADER_STATUS_502', '502 Bad Gateway');
94
define('HTTP_HEADER_STATUS_502', '502 Bad Gateway');
95
define('HTTP_HEADER_STATUS_503', '503 Service Unavailable');
95
define('HTTP_HEADER_STATUS_503', '503 Service Unavailable');
96
define('HTTP_HEADER_STATUS_504', '504 Gateway Time-out');
96
define('HTTP_HEADER_STATUS_504', '504 Gateway Time-out');
97
define('HTTP_HEADER_STATUS_505', '505 HTTP Version not supported');
97
define('HTTP_HEADER_STATUS_505', '505 HTTP Version not supported');
98
define('HTTP_HEADER_STATUS_507', '507 Insufficient Storage');
98
define('HTTP_HEADER_STATUS_507', '507 Insufficient Storage');
99
define('HTTP_HEADER_STATUS_SERVER_ERROR',5);
99
define('HTTP_HEADER_STATUS_SERVER_ERROR',5);
100
/**#@-*/
100
/**#@-*/
101
 
101
 
102
/**
102
/**
103
 * HTTP_Header
103
 * HTTP_Header
104
 * 
104
 * 
105
 * @package     HTTP_Header
105
 * @package     HTTP_Header
106
 * @category    HTTP
106
 * @category    HTTP
107
 * @access      public
107
 * @access      public
108
 * @version     $Revision$
108
 * @version     $Revision$
109
 */
109
 */
110
class HTTP_Header extends HTTP
110
class HTTP_Header extends HTTP
111
{
111
{
112
    /**
112
    /**
113
     * Default Headers
113
     * Default Headers
114
     * 
114
     * 
115
     * The values that are set as default, are the same as PHP sends by default.
115
     * The values that are set as default, are the same as PHP sends by default.
116
     * 
116
     * 
117
     * @var     array
117
     * @var     array
118
     * @access  private
118
     * @access  private
119
     */
119
     */
120
    var $_headers = array(
120
    var $_headers = array(
121
        'content-type'  =>  'text/html',
121
        'content-type'  =>  'text/html',
122
        'pragma'        =>  'no-cache',
122
        'pragma'        =>  'no-cache',
123
        'cache-control' =>  'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
123
        'cache-control' =>  'no-store, no-cache, must-revalidate, post-check=0, pre-check=0'
124
    );
124
    );
125
 
125
 
126
    /**
126
    /**
127
     * HTTP version
127
     * HTTP version
128
     * 
128
     * 
129
     * @var     string
129
     * @var     string
130
     * @access  private
130
     * @access  private
131
     */
131
     */
132
    var $_httpVersion = '1.0';
132
    var $_httpVersion = '1.0';
133
 
133
 
134
    /**
134
    /**
135
     * Constructor
135
     * Constructor
136
     *
136
     *
137
     * Sets HTTP version.
137
     * Sets HTTP version.
138
     * 
138
     * 
139
     * @access  public
139
     * @access  public
140
     * @return  object  HTTP_Header
140
     * @return  object  HTTP_Header
141
     */
141
     */
142
    function HTTP_Header()
142
    function __construct()
143
    {
143
    {
144
        if (isset($_SERVER['SERVER_PROTOCOL'])) {
144
        if (isset($_SERVER['SERVER_PROTOCOL'])) {
145
            $this->setHttpVersion(substr($_SERVER['SERVER_PROTOCOL'], -3));
145
            $this->setHttpVersion(substr($_SERVER['SERVER_PROTOCOL'], -3));
146
        }
146
        }
147
    }
147
    }
148
    
148
    
149
    /**
149
    /**
150
     * Set HTTP version
150
     * Set HTTP version
151
     *
151
     *
152
     * @access  public
152
     * @access  public
153
     * @return  bool    Returns true on success or false if version doesn't 
153
     * @return  bool    Returns true on success or false if version doesn't 
154
     *                  match 1.0 or 1.1 (note: 1 will result in 1.0)
154
     *                  match 1.0 or 1.1 (note: 1 will result in 1.0)
155
     * @param   mixed   $version HTTP version, either 1.0 or 1.1
155
     * @param   mixed   $version HTTP version, either 1.0 or 1.1
156
     */
156
     */
157
    function setHttpVersion($version)
157
    function setHttpVersion($version)
158
    {
158
    {
159
        $version = round((float) $version, 1);
159
        $version = round((float) $version, 1);
160
        if ($version < 1.0 || $version > 1.1) {
160
        if ($version < 1.0 || $version > 1.1) {
161
            return false;
161
            return false;
162
        }
162
        }
163
        $this->_httpVersion = sprintf('%0.1f', $version);
163
        $this->_httpVersion = sprintf('%0.1f', $version);
164
        return true;
164
        return true;
165
    }
165
    }
166
    
166
    
167
    /**
167
    /**
168
     * Get HTTP version
168
     * Get HTTP version
169
     *
169
     *
170
     * @access  public
170
     * @access  public
171
     * @return  string
171
     * @return  string
172
     */
172
     */
173
    function getHttpVersion()
173
    function getHttpVersion()
174
    {
174
    {
175
        return $this->_httpVersion;
175
        return $this->_httpVersion;
176
    }
176
    }
177
    
177
    
178
    /**
178
    /**
179
     * Set Header
179
     * Set Header
180
     * 
180
     * 
181
     * The default value for the Last-Modified header will be current
181
     * The default value for the Last-Modified header will be current
182
     * date and atime if $value is omitted.
182
     * date and atime if $value is omitted.
183
     * 
183
     * 
184
     * @access  public
184
     * @access  public
185
     * @return  bool    Returns true on success or false if $key was empty or
185
     * @return  bool    Returns true on success or false if $key was empty or
186
     *                  $value was not of an scalar type.
186
     *                  $value was not of an scalar type.
187
     * @param   string  $key The name of the header.
187
     * @param   string  $key The name of the header.
188
     * @param   string  $value The value of the header. (NULL to unset header)
188
     * @param   string  $value The value of the header. (NULL to unset header)
189
     */
189
     */
190
    function setHeader($key, $value = null)
190
    function setHeader($key, $value = null)
191
    {
191
    {
192
        if (empty($key) || (isset($value) && !is_scalar($value))) {
192
        if (empty($key) || (isset($value) && !is_scalar($value))) {
193
            return false;
193
            return false;
194
        }
194
        }
195
        
195
        
196
        $key = strToLower($key);
196
        $key = strToLower($key);
197
        if ($key == 'last-modified') {
197
        if ($key == 'last-modified') {
198
            if (!isset($value)) {
198
            if (!isset($value)) {
199
                $value = HTTP::Date(time());
199
                $value = HTTP::Date(time());
200
            } elseif (is_numeric($value)) {
200
            } elseif (is_numeric($value)) {
201
                $value = HTTP::Date($value);
201
                $value = HTTP::Date($value);
202
            }
202
            }
203
        }
203
        }
204
        
204
        
205
        if (isset($value)) {
205
        if (isset($value)) {
206
            $this->_headers[$key] = $value;
206
            $this->_headers[$key] = $value;
207
        } else {
207
        } else {
208
            unset($this->_headers[$key]);
208
            unset($this->_headers[$key]);
209
        }
209
        }
210
        
210
        
211
        return true;
211
        return true;
212
    }
212
    }
213
 
213
 
214
    /**
214
    /**
215
     * Get Header
215
     * Get Header
216
     * 
216
     * 
217
     * If $key is omitted, all stored headers will be returned.
217
     * If $key is omitted, all stored headers will be returned.
218
     * 
218
     * 
219
     * @access  public
219
     * @access  public
220
     * @return  mixed   Returns string value of the requested header,
220
     * @return  mixed   Returns string value of the requested header,
221
     *                  array values of all headers or false if header $key
221
     *                  array values of all headers or false if header $key
222
     *                  is not set.
222
     *                  is not set.
223
     * @param   string  $key    The name of the header to fetch.
223
     * @param   string  $key    The name of the header to fetch.
224
     */
224
     */
225
    function getHeader($key = null)
225
    function getHeader($key = null)
226
    {
226
    {
227
        if (!isset($key)) {
227
        if (!isset($key)) {
228
            return $this->_headers;
228
            return $this->_headers;
229
        }
229
        }
230
        
230
        
231
        $key = strToLower($key);
231
        $key = strToLower($key);
232
        
232
        
233
        if (!isset($this->_headers[$key])) {
233
        if (!isset($this->_headers[$key])) {
234
            return false;
234
            return false;
235
        }
235
        }
236
        
236
        
237
        return $this->_headers[$key];
237
        return $this->_headers[$key];
238
    }
238
    }
239
 
239
 
240
    /**
240
    /**
241
     * Send Headers
241
     * Send Headers
242
     * 
242
     * 
243
     * Send out the header that you set via setHeader().
243
     * Send out the header that you set via setHeader().
244
     * 
244
     * 
245
     * @access  public
245
     * @access  public
246
     * @return  bool    Returns true on success or false if headers are already
246
     * @return  bool    Returns true on success or false if headers are already
247
     *                  sent.
247
     *                  sent.
248
     * @param   array   $keys Headers to (not) send, see $include.
248
     * @param   array   $keys Headers to (not) send, see $include.
249
     * @param   array   $include If true only $keys matching headers will be
249
     * @param   array   $include If true only $keys matching headers will be
250
     *                  sent, if false only header not matching $keys will be
250
     *                  sent, if false only header not matching $keys will be
251
     *                  sent.
251
     *                  sent.
252
     */
252
     */
253
    function sendHeaders($keys = array(), $include = true)
253
    function sendHeaders($keys = array(), $include = true)
254
    {
254
    {
255
        if (headers_sent()) {
255
        if (headers_sent()) {
256
            return false;
256
            return false;
257
        }
257
        }
258
        
258
        
259
        if (count($keys)) {
259
        if (count($keys)) {
260
            array_change_key_case($keys, CASE_LOWER);
260
            array_change_key_case($keys, CASE_LOWER);
261
            foreach ($this->_headers as $key => $value) {
261
            foreach ($this->_headers as $key => $value) {
262
                if ($include ? in_array($key, $keys) : !in_array($key, $keys)) {
262
                if ($include ? in_array($key, $keys) : !in_array($key, $keys)) {
263
                    header($key .': '. $value);
263
                    header($key .': '. $value);
264
                }
264
                }
265
            }
265
            }
266
        } else {
266
        } else {
267
            foreach ($this->_headers as $header => $value) {
267
            foreach ($this->_headers as $header => $value) {
268
                header($header .': '. $value);
268
                header($header .': '. $value);
269
            }
269
            }
270
        }
270
        }
271
        return true;
271
        return true;
272
    }
272
    }
273
 
273
 
274
    /**
274
    /**
275
     * Send Satus Code
275
     * Send Satus Code
276
     * 
276
     * 
277
     * Send out the given HTTP-Status code. Use this for example when you 
277
     * Send out the given HTTP-Status code. Use this for example when you 
278
     * want to tell the client this page is cached, then you would call 
278
     * want to tell the client this page is cached, then you would call 
279
     * sendStatusCode(304).
279
     * sendStatusCode(304).
280
     *
280
     *
281
     * @see HTTP_Header_Cache::exitIfCached()
281
     * @see HTTP_Header_Cache::exitIfCached()
282
     * 
282
     * 
283
     * @access  public
283
     * @access  public
284
     * @return  bool    Returns true on success or false if headers are already
284
     * @return  bool    Returns true on success or false if headers are already
285
     *                  sent.
285
     *                  sent.
286
     * @param   int     $code The status code to send, i.e. 404, 304, 200, etc.
286
     * @param   int     $code The status code to send, i.e. 404, 304, 200, etc.
287
     */
287
     */
288
    function sendStatusCode($code)
288
    function sendStatusCode($code)
289
    {
289
    {
290
        if (headers_sent()) {
290
        if (headers_sent()) {
291
            return false;
291
            return false;
292
        }
292
        }
293
        
293
        
294
        if ($code == (int) $code && defined('HTTP_HEADER_STATUS_'. $code)) {
294
        if ($code == (int) $code && defined('HTTP_HEADER_STATUS_'. $code)) {
295
            $code = constant('HTTP_HEADER_STATUS_'. $code);
295
            $code = constant('HTTP_HEADER_STATUS_'. $code);
296
        }
296
        }
297
        
297
        
298
        if (strncasecmp(PHP_SAPI, 'cgi', 3)) {
298
        if (strncasecmp(PHP_SAPI, 'cgi', 3)) {
299
            header('HTTP/'. $this->_httpVersion .' '. $code);
299
            header('HTTP/'. $this->_httpVersion .' '. $code);
300
        } else {
300
        } else {
301
            header('Status: '. $code);
301
            header('Status: '. $code);
302
        }
302
        }
303
        return true;
303
        return true;
304
    }
304
    }
305
 
305
 
306
    /**
306
    /**
307
     * Date to Timestamp
307
     * Date to Timestamp
308
     * 
308
     * 
309
     * Converts dates like
309
     * Converts dates like
310
     *      Mon, 31 Mar 2003 15:26:34 GMT
310
     *      Mon, 31 Mar 2003 15:26:34 GMT
311
     *      Tue, 15 Nov 1994 12:45:26 GMT
311
     *      Tue, 15 Nov 1994 12:45:26 GMT
312
     * into a timestamp, strtotime() didn't do it in older versions.
312
     * into a timestamp, strtotime() didn't do it in older versions.
313
     *
313
     *
314
     * @deprecated      Use PHPs strtotime() instead.
314
     * @deprecated      Use PHPs strtotime() instead.
315
     * @access  public
315
     * @access  public
316
     * @return  mixed   Returns int unix timestamp or false if the date doesn't
316
     * @return  mixed   Returns int unix timestamp or false if the date doesn't
317
     *                  seem to be a valid GMT date.
317
     *                  seem to be a valid GMT date.
318
     * @param   string  $date The GMT date.
318
     * @param   string  $date The GMT date.
319
     */
319
     */
320
    function dateToTimestamp($date)
320
    function dateToTimestamp($date)
321
    {
321
    {
322
        static $months = array(
322
        static $months = array(
323
            null => 0, 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4,
323
            null => 0, 'Jan' => 1, 'Feb' => 2, 'Mar' => 3, 'Apr' => 4,
324
            'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9,
324
            'May' => 5, 'Jun' => 6, 'Jul' => 7, 'Aug' => 8, 'Sep' => 9,
325
            'Oct' => 10, 'Nov' => 11, 'Dec' => 12
325
            'Oct' => 10, 'Nov' => 11, 'Dec' => 12
326
        );
326
        );
327
        
327
        
328
        if (-1 < $timestamp = strToTime($date)) {
328
        if (-1 < $timestamp = strToTime($date)) {
329
            return $timestamp;
329
            return $timestamp;
330
        }
330
        }
331
        
331
        
332
        if (!preg_match('~[^,]*,\s(\d+)\s(\w+)\s(\d+)\s(\d+):(\d+):(\d+).*~',
332
        if (!preg_match('~[^,]*,\s(\d+)\s(\w+)\s(\d+)\s(\d+):(\d+):(\d+).*~',
333
            $date, $m)) {
333
            $date, $m)) {
334
            return false;
334
            return false;
335
        }
335
        }
336
        
336
        
337
        // [0] => Mon, 31 Mar 2003 15:42:55 GMT
337
        // [0] => Mon, 31 Mar 2003 15:42:55 GMT
338
        // [1] => 31 [2] => Mar [3] => 2003 [4] => 15 [5] => 42 [6] => 55
338
        // [1] => 31 [2] => Mar [3] => 2003 [4] => 15 [5] => 42 [6] => 55
339
        return mktime($m[4], $m[5], $m[6], $months[$m[2]], $m[1], $m[3]);
339
        return mktime($m[4], $m[5], $m[6], $months[$m[2]], $m[1], $m[3]);
340
    }
340
    }
341
 
341
 
342
    /**
342
    /**
343
     * Redirect
343
     * Redirect
344
     * 
344
     * 
345
     * This function redirects the client. This is done by issuing a Location 
345
     * This function redirects the client. This is done by issuing a Location 
346
     * header and exiting.  Additionally to HTTP::redirect() you can also add 
346
     * header and exiting.  Additionally to HTTP::redirect() you can also add 
347
     * parameters to the url.
347
     * parameters to the url.
348
     * 
348
     * 
349
     * If you dont need parameters to be added, simply use HTTP::redirect()
349
     * If you dont need parameters to be added, simply use HTTP::redirect()
350
     * otherwise use HTTP_Header::redirect().
350
     * otherwise use HTTP_Header::redirect().
351
     *
351
     *
352
     * @see     HTTP::redirect()
352
     * @see     HTTP::redirect()
353
     * @author  Wolfram Kriesing <wk@visionp.de>
353
     * @author  Wolfram Kriesing <wk@visionp.de>
354
     * @access  public
354
     * @access  public
355
     * @return  void
355
     * @return  void
356
     * @param   string  $url The URL to redirect to, if none is given it 
356
     * @param   string  $url The URL to redirect to, if none is given it 
357
     *                  redirects to the current page.
357
     *                  redirects to the current page.
358
     * @param   array   $param Array of query string parameters to add; usually
358
     * @param   array   $param Array of query string parameters to add; usually
359
     *                  a set of key => value pairs; if an array entry consists
359
     *                  a set of key => value pairs; if an array entry consists
360
     *                  only of an value it is used as key and the respective
360
     *                  only of an value it is used as key and the respective
361
     *                  value is fetched from $GLOBALS[$value]
361
     *                  value is fetched from $GLOBALS[$value]
362
     * @param   bool    $session Whether the session name/id should be added
362
     * @param   bool    $session Whether the session name/id should be added
363
     */
363
     */
364
    function redirect($url = null, $param = array(), $session = false)
364
    function redirect($url = null, $param = array(), $session = false)
365
    {
365
    {
366
        if (!isset($url)) {
366
        if (!isset($url)) {
367
            $url = $_SERVER['PHP_SELF'];
367
            $url = $_SERVER['PHP_SELF'];
368
        }
368
        }
369
        
369
        
370
        $qs = array();
370
        $qs = array();
371
 
371
 
372
        if ($session) {
372
        if ($session) {
373
            $qs[] = session_name() .'='. session_id();
373
            $qs[] = session_name() .'='. session_id();
374
        }
374
        }
375
 
375
 
376
        if (is_array($param) && count($param)) {
376
        if (is_array($param) && count($param)) {
377
            if (count($param)) {
377
            if (count($param)) {
378
                foreach ($param as $key => $val) {
378
                foreach ($param as $key => $val) {
379
                    if (is_string($key)) {
379
                    if (is_string($key)) {
380
                        $qs[] = urlencode($key) .'='. urlencode($val);
380
                        $qs[] = urlencode($key) .'='. urlencode($val);
381
                    } else {
381
                    } else {
382
                        $qs[] = urlencode($val) .'='. urlencode(@$GLOBALS[$val]);
382
                        $qs[] = urlencode($val) .'='. urlencode(@$GLOBALS[$val]);
383
                    }
383
                    }
384
                }
384
                }
385
            }
385
            }
386
        }
386
        }
387
        
387
        
388
        if ($qstr = implode('&', $qs)) {
388
        if ($qstr = implode('&', $qs)) {
389
            $purl = parse_url($url);
389
            $purl = parse_url($url);
390
            $url .= (isset($purl['query']) ? '&' : '?') . $qstr;
390
            $url .= (isset($purl['query']) ? '&' : '?') . $qstr;
391
        }
391
        }
392
 
392
 
393
        parent::redirect($url);
393
        parent::redirect($url);
394
    }
394
    }
395
 
395
 
396
    /**#@+
396
    /**#@+
397
     * @author  Davey Shafik <davey@php.net>
397
     * @author  Davey Shafik <davey@php.net>
398
     * @param   int $http_code HTTP Code to check
398
     * @param   int $http_code HTTP Code to check
399
     * @access  public
399
     * @access  public
400
     */
400
     */
401
 
401
 
402
    /**
402
    /**
403
     * Return HTTP Status Code Type
403
     * Return HTTP Status Code Type
404
     *
404
     *
405
     * @return int|false
405
     * @return int|false
406
     */
406
     */
407
    function getStatusType($http_code) 
407
    function getStatusType($http_code) 
408
    {
408
    {
409
        if(is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code) || defined($http_code)) {
409
        if(is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code) || defined($http_code)) {
410
            $type = substr($http_code,0,1);
410
            $type = substr($http_code,0,1);
411
            switch ($type) {
411
            switch ($type) {
412
                case HTTP_HEADER_STATUS_INFORMATIONAL:
412
                case HTTP_HEADER_STATUS_INFORMATIONAL:
413
                case HTTP_HEADER_STATUS_SUCCESSFUL:
413
                case HTTP_HEADER_STATUS_SUCCESSFUL:
414
                case HTTP_HEADER_STATUS_REDIRECT:
414
                case HTTP_HEADER_STATUS_REDIRECT:
415
                case HTTP_HEADER_STATUS_CLIENT_ERROR:
415
                case HTTP_HEADER_STATUS_CLIENT_ERROR:
416
                case HTTP_HEADER_STATUS_SERVER_ERROR:
416
                case HTTP_HEADER_STATUS_SERVER_ERROR:
417
                    return $type;
417
                    return $type;
418
                    break;
418
                    break;
419
                default:
419
                default:
420
                    return false;
420
                    return false;
421
                    break;
421
                    break;
422
            }
422
            }
423
        } else {
423
        } else {
424
            return false;
424
            return false;
425
        }
425
        }
426
    }
426
    }
427
 
427
 
428
    /**
428
    /**
429
     * Return Status Code Message
429
     * Return Status Code Message
430
     *
430
     *
431
     * @return string|false
431
     * @return string|false
432
     */
432
     */
433
    function getStatusText($http_code) 
433
    function getStatusText($http_code) 
434
    {
434
    {
435
        if ($this->getStatusType($http_code)) {
435
        if ($this->getStatusType($http_code)) {
436
            if (is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code)) {
436
            if (is_int($http_code) && defined('HTTP_HEADER_STATUS_' .$http_code)) {
437
                return substr(constant('HTTP_HEADER_STATUS_' .$http_code),4);
437
                return substr(constant('HTTP_HEADER_STATUS_' .$http_code),4);
438
            } else {
438
            } else {
439
                return substr($http_code,4);
439
                return substr($http_code,4);
440
            }
440
            }
441
        } else {
441
        } else {
442
            return false;
442
            return false;
443
        }
443
        }
444
    }
444
    }
445
 
445
 
446
    /**
446
    /**
447
     * Checks if HTTP Status code is Information (1xx)
447
     * Checks if HTTP Status code is Information (1xx)
448
     *
448
     *
449
     * @return boolean
449
     * @return boolean
450
     */
450
     */
451
    function isInformational($http_code) 
451
    function isInformational($http_code) 
452
    {
452
    {
453
        if ($status_type = $this->getStatusType($http_code)) {
453
        if ($status_type = $this->getStatusType($http_code)) {
454
            return $status_type{0} == HTTP_HEADER_STATUS_INFORMATIONAL;
454
            return $status_type{0} == HTTP_HEADER_STATUS_INFORMATIONAL;
455
        } else {
455
        } else {
456
            return false;
456
            return false;
457
        }
457
        }
458
    }
458
    }
459
 
459
 
460
    /**
460
    /**
461
     * Checks if HTTP Status code is Successful (2xx)
461
     * Checks if HTTP Status code is Successful (2xx)
462
     *
462
     *
463
     * @return boolean
463
     * @return boolean
464
     */
464
     */
465
    function isSuccessful($http_code) 
465
    function isSuccessful($http_code) 
466
    {
466
    {
467
        if ($status_type = $this->getStatusType($http_code)) {
467
        if ($status_type = $this->getStatusType($http_code)) {
468
            return $status_type{0} == HTTP_HEADER_STATUS_SUCCESSFUL;
468
            return $status_type{0} == HTTP_HEADER_STATUS_SUCCESSFUL;
469
        } else {
469
        } else {
470
            return false;
470
            return false;
471
        }
471
        }
472
    }
472
    }
473
 
473
 
474
    /**
474
    /**
475
     * Checks if HTTP Status code is a Redirect (3xx)
475
     * Checks if HTTP Status code is a Redirect (3xx)
476
     *
476
     *
477
     * @return boolean
477
     * @return boolean
478
     */
478
     */
479
    function isRedirect($http_code) 
479
    function isRedirect($http_code) 
480
    {
480
    {
481
        if ($status_type = $this->getStatusType($http_code)) {
481
        if ($status_type = $this->getStatusType($http_code)) {
482
            return $status_type{0} == HTTP_HEADER_STATUS_REDIRECT;
482
            return $status_type{0} == HTTP_HEADER_STATUS_REDIRECT;
483
        } else {
483
        } else {
484
            return false;
484
            return false;
485
        }
485
        }
486
    }
486
    }
487
 
487
 
488
    /**
488
    /**
489
     * Checks if HTTP Status code is a Client Error (4xx)
489
     * Checks if HTTP Status code is a Client Error (4xx)
490
     *
490
     *
491
     * @return boolean
491
     * @return boolean
492
     */
492
     */
493
    function isClientError($http_code) 
493
    function isClientError($http_code) 
494
    {
494
    {
495
        if ($status_type = $this->getStatusType($http_code)) {
495
        if ($status_type = $this->getStatusType($http_code)) {
496
            return $status_type{0} == HTTP_HEADER_STATUS_CLIENT_ERROR;
496
            return $status_type{0} == HTTP_HEADER_STATUS_CLIENT_ERROR;
497
        } else {
497
        } else {
498
            return false;
498
            return false;
499
        }
499
        }
500
    }
500
    }
501
 
501
 
502
    /**
502
    /**
503
     * Checks if HTTP Status code is Server Error (5xx)
503
     * Checks if HTTP Status code is Server Error (5xx)
504
     *
504
     *
505
     * @return boolean
505
     * @return boolean
506
     */
506
     */
507
    function isServerError($http_code) 
507
    function isServerError($http_code) 
508
    {
508
    {
509
        if ($status_type = $this->getStatusType($http_code)) {
509
        if ($status_type = $this->getStatusType($http_code)) {
510
            return $status_type{0} == HTTP_HEADER_STATUS_SERVER_ERROR;
510
            return $status_type{0} == HTTP_HEADER_STATUS_SERVER_ERROR;
511
        } else {
511
        } else {
512
            return false;
512
            return false;
513
        }
513
        }
514
    }
514
    }
515
 
515
 
516
    /**
516
    /**
517
     * Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
517
     * Checks if HTTP Status code is Server OR Client Error (4xx or 5xx)
518
     *
518
     *
519
     * @return boolean
519
     * @return boolean
520
     */
520
     */
521
    function isError($http_code) 
521
    function isError($http_code) 
522
    {
522
    {
523
        if ($status_type = $this->getStatusType($http_code)) {
523
        if ($status_type = $this->getStatusType($http_code)) {
524
            return (($status_type == HTTP_HEADER_STATUS_CLIENT_ERROR) || ($status_type == HTTP_HEADER_STATUS_SERVER_ERROR)) ? true : false;
524
            return (($status_type == HTTP_HEADER_STATUS_CLIENT_ERROR) || ($status_type == HTTP_HEADER_STATUS_SERVER_ERROR)) ? true : false;
525
        } else {
525
        } else {
526
            return false;
526
            return false;
527
        }
527
        }
528
    }
528
    }
529
    /**#@-*/
529
    /**#@-*/
530
}
530
}
531
?>
531
?>