Posted By

olive on 08/22/06


Tagged

cookie


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

vali29
skywalker


cookies


 / Published in: PHP
 

  1. //set
  2. <script>
  3. <!-- begin script
  4. //
  5. // Cookie Functions - Second Helping (21-Jan-96)
  6. // Written by: Bill Dortch, hIdaho Design <[email protected]>
  7. // The following functions are released to the public domain.
  8.  
  9. //
  10. // "Internal" function to return the decoded value of a cookie
  11. //
  12. function getCookieVal (offset) {
  13. var endstr = document.cookie.indexOf (";", offset);
  14. if (endstr == -1)
  15. endstr = document.cookie.length;
  16. return unescape(document.cookie.substring(offset, endstr));
  17. }
  18.  
  19. //
  20. // Function to return the value of the cookie specified by "name".
  21. // name - String object containing the cookie name.
  22. // returns - String object containing the cookie value, or null if
  23. // the cookie does not exist.
  24. //
  25. function GetCookie (name) {
  26. var arg = name + "=";
  27. var alen = arg.length;
  28. var clen = document.cookie.length;
  29. var i = 0;
  30. while (i < clen) {
  31. var j = i + alen;
  32. if (document.cookie.substring(i, j) == arg)
  33. return getCookieVal (j);
  34. i = document.cookie.indexOf(" ", i) + 1;
  35. if (i == 0) break;
  36. }
  37. return null;
  38. }
  39.  
  40. //
  41. // Function to create or update a cookie.
  42. // name - String object object containing the cookie name.
  43. // value - String object containing the cookie value. May contain
  44. // any valid string characters.
  45. // [expires] - Date object containing the expiration data of the cookie. If
  46. // omitted or null, expires the cookie at the end of the current session.
  47. // [path] - String object indicating the path for which the cookie is valid.
  48. // If omitted or null, uses the path of the calling document.
  49. // [domain] - String object indicating the domain for which the cookie is
  50. // valid. If omitted or null, uses the domain of the calling document.
  51. // [secure] - Boolean (true/false) value indicating whether cookie transmission
  52. // requires a secure channel (HTTPS).
  53. //
  54. // The first two parameters are required. The others, if supplied, must
  55. // be passed in the order listed above. To omit an unused optional field,
  56. // use null as a place holder. For example, to call SetCookie using name,
  57. // value and path, you would code:
  58. //
  59. // SetCookie ("myCookieName", "myCookieValue", null, "/");
  60. //
  61. // Note that trailing omitted parameters do not require a placeholder.
  62. //
  63. // To set a secure cookie for path "/myPath", that expires after the
  64. // current session, you might code:
  65. //
  66. // SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true);
  67. //
  68. function SetCookie (name, value) {
  69. var argv = SetCookie.arguments;
  70. var argc = SetCookie.arguments.length;
  71. var expires = (argc > 2) ? argv[2] : null;
  72. var path = (argc > 3) ? argv[3] : null;
  73. var domain = (argc > 4) ? argv[4] : null;
  74. var secure = (argc > 5) ? argv[5] : false;
  75. document.cookie = name + "=" + escape (value) +
  76. ((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +
  77. ((path == null) ? "" : ("; path=" + path)) +
  78. ((domain == null) ? "" : ("; domain=" + domain)) +
  79. ((secure == true) ? "; secure" : "");
  80. }
  81.  
  82. // Function to delete a cookie. (Sets expiration date to current date/time)
  83. // name - String object containing the cookie name
  84. //
  85. function DeleteCookie (name) {
  86. var exp = new Date();
  87. exp.setTime (exp.getTime() - 1); // This cookie is history
  88. var cval = GetCookie (name);
  89. if (cval != null)
  90. document.cookie = name + "=" + cval + "; expires=" + exp.toGMTString();
  91. }
  92.  
  93. // end script -->
  94.  
  95. </script>
  96. <?
  97. include ("docs/inc/defConstantes.inc");
  98. $domaine=COOKIE_DOMAIN;?>
  99. <script>SetCookie ('ope<?=$ope_ref?>','0',null,'/','<?=$domaine?>');</script>
  100. //Ou
  101. include ("docs/inc/defConstantes.inc");
  102. $domaine=COOKIE_DOMAIN;
  103. setcookie("ck_imgr", "1",null,"/",$domaine, 0);
  104.  
  105. //lire
  106. $_COOKIE["ck_imgr"]

Report this snippet  

You need to login to post a comment.