/halogy/helpers/cookie_helper.php

https://bitbucket.org/haloweb/halogy-1.0/ · PHP · 144 lines · 66 code · 17 blank · 61 comment · 20 complexity · 58bb0ed04eb060f8990ca8dad3de362a MD5 · raw file

  1. <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
  2. /**
  3. * CodeIgniter
  4. *
  5. * An open source application development framework for PHP 4.3.2 or newer
  6. *
  7. * @package CodeIgniter
  8. * @author ExpressionEngine Dev Team
  9. * @copyright Copyright (c) 2008 - 2009, 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 = '')
  44. {
  45. if (is_array($name))
  46. {
  47. foreach (array('value', 'expire', 'domain', 'path', 'prefix', 'name') as $item)
  48. {
  49. if (isset($name[$item]))
  50. {
  51. $$item = $name[$item];
  52. }
  53. }
  54. }
  55. // Set the config file options
  56. $CI =& get_instance();
  57. if ($prefix == '' AND $CI->config->item('cookie_prefix') != '')
  58. {
  59. $prefix = $CI->config->item('cookie_prefix');
  60. }
  61. if ($domain == '' AND $CI->config->item('cookie_domain') != '')
  62. {
  63. $domain = $CI->config->item('cookie_domain');
  64. }
  65. if ($path == '/' AND $CI->config->item('cookie_path') != '/')
  66. {
  67. $path = $CI->config->item('cookie_path');
  68. }
  69. if ( ! is_numeric($expire))
  70. {
  71. $expire = time() - 86500;
  72. }
  73. else
  74. {
  75. if ($expire > 0)
  76. {
  77. $expire = time() + $expire;
  78. }
  79. else
  80. {
  81. $expire = 0;
  82. }
  83. }
  84. setcookie($prefix.$name, $value, $expire, $path, $domain, 0);
  85. }
  86. }
  87. // --------------------------------------------------------------------
  88. /**
  89. * Fetch an item from the COOKIE array
  90. *
  91. * @access public
  92. * @param string
  93. * @param bool
  94. * @return mixed
  95. */
  96. if ( ! function_exists('get_cookie'))
  97. {
  98. function get_cookie($index = '', $xss_clean = FALSE)
  99. {
  100. $CI =& get_instance();
  101. $prefix = '';
  102. if ( ! isset($_COOKIE[$index]) && config_item('cookie_prefix') != '')
  103. {
  104. $prefix = config_item('cookie_prefix');
  105. }
  106. return $CI->input->cookie($prefix.$index, $xss_clean);
  107. }
  108. }
  109. // --------------------------------------------------------------------
  110. /**
  111. * Delete a COOKIE
  112. *
  113. * @param mixed
  114. * @param string the cookie domain. Usually: .yourdomain.com
  115. * @param string the cookie path
  116. * @param string the cookie prefix
  117. * @return void
  118. */
  119. if ( ! function_exists('delete_cookie'))
  120. {
  121. function delete_cookie($name = '', $domain = '', $path = '/', $prefix = '')
  122. {
  123. set_cookie($name, '', '', $domain, $path, $prefix);
  124. }
  125. }
  126. /* End of file cookie_helper.php */
  127. /* Location: ./system/helpers/cookie_helper.php */