cookie_helper.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 5.1.6 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2011, EllisLab, Inc.
  10. * @license http://codeigniter.com/user_guide/license.html
  11. * @link http://codeigniter.com
  12. * @since Version 1.0
  13. * @filesource
  14. */
  15. // ------------------------------------------------------------------------
  16. /**
  17. * CodeIgniter Cookie Helpers
  18. *
  19. * @package CodeIgniter
  20. * @subpackage Helpers
  21. * @category Helpers
  22. * @author ExpressionEngine Dev Team
  23. * @link http://codeigniter.com/user_guide/helpers/cookie_helper.html
  24. */
  25. // ------------------------------------------------------------------------
  26. /**
  27. * Set cookie
  28. *
  29. * Accepts six parameter, or you can submit an associative
  30. * array in the first parameter containing all the values.
  31. *
  32. * @access public
  33. * @param mixed
  34. * @param string the value of the cookie
  35. * @param string the number of seconds until expiration
  36. * @param string the cookie domain. Usually: .yourdomain.com
  37. * @param string the cookie path
  38. * @param string the cookie prefix
  39. * @return void
  40. */
  41. if ( ! function_exists('set_cookie'))
  42. {
  43. function set_cookie($name = '', $value = '', $expire = '', $domain = '', $path = '/', $prefix = '', $secure = FALSE)
  44. {
  45. // Set the config file options
  46. $CI =& get_instance();
  47. $CI->input->set_cookie($name, $value, $expire, $domain, $path, $prefix, $secure);
  48. }
  49. }
  50. // --------------------------------------------------------------------
  51. /**
  52. * Fetch an item from the COOKIE array
  53. *
  54. * @access public
  55. * @param string
  56. * @param bool
  57. * @return mixed
  58. */
  59. if ( ! function_exists('get_cookie'))
  60. {
  61. function get_cookie($index = '', $xss_clean = FALSE)
  62. {
  63. $CI =& get_instance();
  64. $prefix = '';
  65. if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '')
  66. {
  67. $prefix = config_item('cookie_prefix');
  68. }
  69. return $CI->input->cookie($prefix.$index, $xss_clean);
  70. }
  71. }
  72. // --------------------------------------------------------------------
  73. /**
  74. * Delete a COOKIE
  75. *
  76. * @param mixed
  77. * @param string the cookie domain. Usually: .yourdomain.com
  78. * @param string the cookie path
  79. * @param string the cookie prefix
  80. * @return void
  81. */
  82. if ( ! function_exists('delete_cookie'))
  83. {
  84. function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
  85. {
  86. set_cookie($name, '', '', $domain, $path, $prefix);
  87. }
  88. }
  89. /* End of file cookie_helper.php */
  90. /* Location: ./system/helpers/cookie_helper.php */