免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 968 | 回复: 1
打印 上一主题 下一主题

php中cookie问题! [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-01-22 11:05 |只看该作者 |倒序浏览
请问各位大侠:

在php中cookie值能否用数组来存储?

如果能的话,如何实现,望赐教!!

谢谢!!!

论坛徽章:
1
技术图书徽章
日期:2013-12-05 23:25:45
2 [报告]
发表于 2005-01-24 16:44 |只看该作者

php中cookie问题!


  1. COOKIE数组

  2. <?PHP
  3. //
  4. // Class: SiteCookie
  5. // Version: 1.0
  6. // Purpose: Easily handle multiple cookies for a site in one browser cookie.
  7. // Whatever you enter with put() is added to the single cookie stored
  8. // when you call set(). The cookie name the browser receives is the
  9. // string specified when creating the object. The constructor reads
  10. // the browser cookie and creates the variables for use in your code.
  11. //
  12. // Usage:
  13. //
  14. // $cookie=new SiteCookie("mycookie");
  15. //
  16. // $cookie->;put("bob","tom2"); // the difference between using put() and
  17. // $cookie->;put("tom","bob2"); // the setting the val array is that the
  18. // // or you can do: // variables bob and tom are created by
  19. // $cookie->;val["bob"]="tom2"; // put(). By just setting the var array,
  20. // $cookie->;val["tom"]="bob2"; // the variables are not created.
  21. //
  22. // $cookie->;set();
  23. //
  24. // echo $bob;
  25. // echo $tom;
  26. //
  27. // Properties:
  28. //
  29. // $name: the name that the cookie is stored with in the browser.
  30. // $val: an internal array to hold the cookie information.
  31. // $expires: the expiration date of the cookie. default 1 year.
  32. // $dir: the http dir that cookie is set to. default is /.
  33. // $site: the domain for the cookie. default is none. The browser
  34. // will use the current domain.

  35. class SiteCookie {

  36. var $name="";
  37. var $val=array();
  38. var $expires=time()+ 31536000; // one year
  39. var $dir='/'; // all dirs
  40. var $site='';

  41. function SiteCookie($cname, $cexpires="", $cdir=""){
  42. GLOBAL $$cname
  43. $this->;name=$cname;
  44. if($cexpires) $this->;expires=$cexpires;
  45. if($cdir) $this->;dir=$cdir;
  46. @parse_str($$cname);
  47. @parse_str(str_replace("GLOBALS[", "val[", $$cname));
  48. $this->;val=$val;
  49. }

  50. function put($var, $value){
  51. GLOBAL $$var;
  52. $$var=$value;
  53. $this->;val["$var"]=$value;
  54. }

  55. function set(){

  56. if(is_array($this->;val)){
  57. reset($this->;val);
  58. $cnt=count($this->;val);
  59. $curr=current($this->;val);
  60. $cookie_val='';
  61. for($x=0;$x<$cnt;$x++){
  62. $key=key($this->;val);
  63. $cookie_val.="GLOBALS[$key]=$curr";
  64. $curr=next($this->;val);
  65. if($curr) $cookie_val.='&';
  66. }
  67. }
  68. setcookie("$this->;name", $cookie_val, $this->;expires, $this->;dir, $this->;site);

  69. }

  70. }

  71. ?>;   


复制代码
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP