blob: 24e243dddb17876dec7a38d29c8bc20a8ba20cf4 [file] [log] [blame]
adminb0dd10f2006-08-25 17:25:49 +00001<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
2/**
3 * Code Igniter
4 *
5 * An open source application development framework for PHP 4.3.2 or newer
6 *
7 * @package CodeIgniter
8 * @author Rick Ellis
9 * @copyright Copyright (c) 2006, pMachine, Inc.
10 * @license http://www.codeignitor.com/user_guide/license.html
11 * @link http://www.codeigniter.com
12 * @since Version 1.0
13 * @filesource
14 */
15
16// ------------------------------------------------------------------------
17
18/**
19 * Code Igniter Cookie Helpers
20 *
21 * @package CodeIgniter
22 * @subpackage Helpers
23 * @category Helpers
24 * @author Rick Ellis
25 * @link http://www.codeigniter.com/user_guide/helpers/cookie_helper.html
26 */
27
28// ------------------------------------------------------------------------
29
30/**
31 * Set cookie
32 *
33 * Accepts six parameter, or you can submit an associative
34 * array in the first parameter containing all the values.
35 *
36 * @access public
37 * @param mixed
38 * @param string the value of the cookie
39 * @param string the number of seconds until expiration
40 * @param string the cookie domain. Usually: .yourdomain.com
41 * @param string the cookie path
42 * @param string the cookie prefix
43 * @return void
44 */
45function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '')
46{
47 if (is_array($name))
48 {
49 foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item)
50 {
51 if (isset($name[$item]))
52 {
53 $$item = $name[$item];
54 }
55 }
56 }
57
58 if ( ! is_numeric($expire))
59 {
60 $expire = time() - 86500;
61 }
62 else
63 {
64 if ($expire > 0)
65 {
66 $expire = time() + $expire;
67 }
68 else
69 {
70 $expire = 0;
71 }
72 }
73
74 setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
75}
76
77?>