Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 2 | /** |
| 3 | * CodeIgniter |
| 4 | * |
Greg Aker | 741de1c | 2010-11-10 14:52:57 -0600 | [diff] [blame] | 5 | * An open source application development framework for PHP 5.1.6 or newer |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 6 | * |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 7 | * NOTICE OF LICENSE |
| 8 | * |
| 9 | * Licensed under the Open Software License version 3.0 |
| 10 | * |
| 11 | * This source file is subject to the Open Software License (OSL 3.0) that is |
| 12 | * bundled with this package in the files license.txt / license.rst. It is |
| 13 | * also available through the world wide web at this URL: |
| 14 | * http://opensource.org/licenses/OSL-3.0 |
| 15 | * If you did not receive a copy of the license and are unable to obtain it |
| 16 | * through the world wide web, please send an email to |
| 17 | * licensing@ellislab.com so we can send you a copy immediately. |
| 18 | * |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 19 | * @package CodeIgniter |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 20 | * @author EllisLab Dev Team |
| 21 | * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc. (http://ellislab.com/) |
| 22 | * @license http://opensource.org/licenses/OSL-3.0 Open Software License (OSL 3.0) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 23 | * @link http://codeigniter.com |
| 24 | * @since Version 1.0 |
| 25 | * @filesource |
| 26 | */ |
| 27 | |
| 28 | // ------------------------------------------------------------------------ |
| 29 | |
| 30 | /** |
| 31 | * CodeIgniter Cookie Helpers |
| 32 | * |
| 33 | * @package CodeIgniter |
| 34 | * @subpackage Helpers |
| 35 | * @category Helpers |
Derek Jones | f4a4bd8 | 2011-10-20 12:18:42 -0500 | [diff] [blame] | 36 | * @author EllisLab Dev Team |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 37 | * @link http://codeigniter.com/user_guide/helpers/cookie_helper.html |
| 38 | */ |
| 39 | |
| 40 | // ------------------------------------------------------------------------ |
| 41 | |
| 42 | /** |
| 43 | * Set cookie |
| 44 | * |
| 45 | * Accepts six parameter, or you can submit an associative |
| 46 | * array in the first parameter containing all the values. |
| 47 | * |
| 48 | * @access public |
| 49 | * @param mixed |
| 50 | * @param string the value of the cookie |
| 51 | * @param string the number of seconds until expiration |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 52 | * @param string the cookie domain. Usually: .yourdomain.com |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 53 | * @param string the cookie path |
| 54 | * @param string the cookie prefix |
| 55 | * @return void |
| 56 | */ |
| 57 | if ( ! function_exists('set_cookie')) |
| 58 | { |
Phil Sturgeon | d8d1e24 | 2011-02-16 17:23:16 +0000 | [diff] [blame] | 59 | function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE) |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 60 | { |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 61 | // Set the config file options |
| 62 | $CI =& get_instance(); |
Phil Sturgeon | d8d1e24 | 2011-02-16 17:23:16 +0000 | [diff] [blame] | 63 | $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 64 | } |
| 65 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 66 | |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 67 | // -------------------------------------------------------------------- |
| 68 | |
| 69 | /** |
| 70 | * Fetch an item from the COOKIE array |
| 71 | * |
| 72 | * @access public |
| 73 | * @param string |
| 74 | * @param bool |
| 75 | * @return mixed |
| 76 | */ |
| 77 | if ( ! function_exists('get_cookie')) |
| 78 | { |
| 79 | function get_cookie($index = '', $xss_clean = FALSE) |
| 80 | { |
Derek Jones | a04cfa7 | 2009-02-10 20:16:57 +0000 | [diff] [blame] | 81 | $CI =& get_instance(); |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 82 | |
Derek Jones | 2c8dc58 | 2009-02-10 20:15:49 +0000 | [diff] [blame] | 83 | $prefix = ''; |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 84 | |
Derek Jones | 2c8dc58 | 2009-02-10 20:15:49 +0000 | [diff] [blame] | 85 | if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '') |
| 86 | { |
| 87 | $prefix = config_item('cookie_prefix'); |
| 88 | } |
Barry Mieny | dd67197 | 2010-10-04 16:33:58 +0200 | [diff] [blame] | 89 | |
Derek Jones | 2c8dc58 | 2009-02-10 20:15:49 +0000 | [diff] [blame] | 90 | return $CI->input->cookie($prefix.$index, $xss_clean); |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 91 | } |
| 92 | } |
| 93 | |
| 94 | // -------------------------------------------------------------------- |
| 95 | |
| 96 | /** |
| 97 | * Delete a COOKIE |
| 98 | * |
| 99 | * @param mixed |
Derek Jones | 37f4b9c | 2011-07-01 17:56:50 -0500 | [diff] [blame] | 100 | * @param string the cookie domain. Usually: .yourdomain.com |
Derek Allard | 2067d1a | 2008-11-13 22:59:24 +0000 | [diff] [blame] | 101 | * @param string the cookie path |
| 102 | * @param string the cookie prefix |
| 103 | * @return void |
| 104 | */ |
| 105 | if ( ! function_exists('delete_cookie')) |
| 106 | { |
| 107 | function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '') |
| 108 | { |
| 109 | set_cookie($name, '', '', $domain, $path, $prefix); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | |
| 114 | /* End of file cookie_helper.php */ |
Derek Jones | a3ffbbb | 2008-05-11 18:18:29 +0000 | [diff] [blame] | 115 | /* Location: ./system/helpers/cookie_helper.php */ |