国内流行的内容管理系统(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.

68 lines
1.8KB

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