国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.9KB

  1. <?php if(!defined('DEDEINC')) exit('dedecms');
  2. /**
  3. * Cookie处理小助手
  4. *
  5. * @version $Id: file.helper.php 1 13:58 2010年7月5日Z tianya $
  6. * @package DedeCMS.Helpers
  7. * @copyright Copyright (c) 2020, DedeBIZ.COM
  8. * @license https://www.dedebiz.com/license
  9. * @link https://www.dedebiz.com
  10. */
  11. /**
  12. * 设置Cookie记录
  13. *
  14. * @param string $key 键
  15. * @param string $value 值
  16. * @param string $kptime 保持时间
  17. * @param string $pa 保存路径
  18. * @return void
  19. */
  20. if ( ! function_exists('PutCookie'))
  21. {
  22. function PutCookie($key, $value, $kptime=0, $pa="/")
  23. {
  24. global $cfg_cookie_encode,$cfg_domain_cookie;
  25. setcookie($key, $value, time()+$kptime, $pa,$cfg_domain_cookie);
  26. setcookie($key.'__ckMd5', substr(md5($cfg_cookie_encode.$value),0,16), time()+$kptime, $pa,$cfg_domain_cookie);
  27. }
  28. }
  29. /**
  30. * 清除Cookie记录
  31. *
  32. * @param $key 键名
  33. * @return void
  34. */
  35. if ( ! function_exists('DropCookie'))
  36. {
  37. function DropCookie($key)
  38. {
  39. global $cfg_domain_cookie;
  40. setcookie($key, '', time()-360000, "/",$cfg_domain_cookie);
  41. setcookie($key.'__ckMd5', '', time()-360000, "/",$cfg_domain_cookie);
  42. }
  43. }
  44. /**
  45. * 获取Cookie记录
  46. *
  47. * @param $key 键名
  48. * @return string
  49. */
  50. if ( ! function_exists('GetCookie'))
  51. {
  52. function GetCookie($key)
  53. {
  54. global $cfg_cookie_encode;
  55. if( !isset($_COOKIE[$key]) || !isset($_COOKIE[$key.'__ckMd5']) )
  56. {
  57. return '';
  58. }
  59. else
  60. {
  61. if($_COOKIE[$key.'__ckMd5']!=substr(md5($cfg_cookie_encode.$_COOKIE[$key]),0,16))
  62. {
  63. return '';
  64. }
  65. else
  66. {
  67. return $_COOKIE[$key];
  68. }
  69. }
  70. }
  71. }