BioTorrents.de’s version of Gazelle
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.

cookie.class.php 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. declare(strict_types=1);
  3. class COOKIE
  4. {
  5. # If true, blocks JS cookie API access by default (can be overridden case by case)
  6. const LIMIT_ACCESS = true;
  7. # In some cases you may desire to prefix your cookies
  8. const PREFIX = '';
  9. /**
  10. * get()
  11. * Untrustworthy user input
  12. */
  13. public function get($Key)
  14. {
  15. if (!isset($_COOKIE[SELF::PREFIX.$Key])) {
  16. return false;
  17. }
  18. return $_COOKIE[SELF::PREFIX.$Key];
  19. }
  20. /**
  21. * set()
  22. * LimitAccess = false allows JS cookie access
  23. */
  24. public function set($Key, $Value, $Seconds = 86400, $LimitAccess = SELF::LIMIT_ACCESS)
  25. {
  26. setcookie(
  27. SELF::PREFIX.$Key,
  28. $Value,
  29. time() + $Seconds,
  30. '/',
  31. SITE_DOMAIN,
  32. $_SERVER['SERVER_PORT'] === '443',
  33. $LimitAccess,
  34. false
  35. );
  36. }
  37. /**
  38. * del()
  39. */
  40. public function del($Key)
  41. {
  42. # 3600s vs. 1s for potential clock desyncs
  43. setcookie(SELF::PREFIX.$Key, '', time() - 24 * 3600);
  44. }
  45. /**
  46. * flush()
  47. */
  48. public function flush()
  49. {
  50. $Cookies = array_keys($_COOKIE);
  51. foreach ($Cookies as $Cookie) {
  52. $this->del($Cookie);
  53. }
  54. }
  55. }