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

67 lines
1.8KB

  1. <?php if (!defined('DEDEINC')) exit('dedebiz');
  2. /**
  3. * Cookie处理小助手
  4. *
  5. * @version $Id: file.helper.php 1 13:58 2010年7月5日Z tianya $
  6. * @package DedeBIZ.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. function PutCookie($key, $value, $kptime = 0, $pa = "/")
  22. {
  23. global $cfg_cookie_encode, $cfg_domain_cookie;
  24. setcookie($key, $value, time() + $kptime, $pa, $cfg_domain_cookie);
  25. setcookie($key . '__ckMd5', substr(md5($cfg_cookie_encode . $value), 0, 16), time() + $kptime, $pa, $cfg_domain_cookie);
  26. }
  27. }
  28. /**
  29. * 清除Cookie记录
  30. *
  31. * @param $key 键名
  32. * @return void
  33. */
  34. if (!function_exists('DropCookie')) {
  35. function DropCookie($key)
  36. {
  37. global $cfg_domain_cookie;
  38. setcookie($key, '', time() - 360000, "/", $cfg_domain_cookie);
  39. setcookie($key . '__ckMd5', '', time() - 360000, "/", $cfg_domain_cookie);
  40. }
  41. }
  42. /**
  43. * 获取Cookie记录
  44. *
  45. * @param $key 键名
  46. * @return string
  47. */
  48. if (!function_exists('GetCookie')) {
  49. function GetCookie($key)
  50. {
  51. global $cfg_cookie_encode;
  52. if (!isset($_COOKIE[$key]) || !isset($_COOKIE[$key . '__ckMd5'])) {
  53. return '';
  54. } else {
  55. if ($_COOKIE[$key . '__ckMd5'] != substr(md5($cfg_cookie_encode . $_COOKIE[$key]), 0, 16)) {
  56. return '';
  57. } else {
  58. return $_COOKIE[$key];
  59. }
  60. }
  61. }
  62. }