cookie_helper.php 2.6 KB

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