| 订阅 | 在线投稿
分享
 
 
当前位置: 王朝网络 >> php >> dong tai wang ye ji shu PHP guan yu cookie he session de fen xi

dong tai wang ye ji shu PHP guan yu cookie he session de fen xi

2008-12-28 07:39:19 编辑來源:互联网 评论
 
 
 
本文为【动态网页技术PHP关于cookie和session的分析】的拼音翻译版
  1. PHP de COOKIE
  cookie shi yi zhong zai yuan cheng liu lan qi duan chu cun shu ju bing yi ci lai gen zong he shi bie yong hu de ji zhi 。
  PHP zai http xie yi de tou xin xi li fa song cookie, yin ci setcookie() han shu bi xu zai qi ta xin xi bei shu chu dao liu lan qi qian tiao yong , zhe he dui header() han shu de xian zhi lei si 。
  1.1 she zhi cookie:
   ke yi yong setcookie() huo setrawcookie() han shu lai she zhi cookie。 ye ke yi tong guo xiang ke hu duan zhi jie fa song http tou lai she zhi .
  1.1.1 shi yong setcookie() han shu she zhi cookie:
  bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure [, bool httponly]]]]]] )
   name: cookie bian liang ming
   value: cookie bian liang de zhi
   expire: you xiao qi jie shu de shi jian ,
   path: you xiao mu lu ,
   domain: you xiao yu ming , ding ji yu wei yi
   secure: ru guo zhi wei 1, ze cookie zhi neng zai https lian jie shang you xiao , ru guo wei mo ren zhi 0, ze http he https dou ke yi .
  li zi :
  <?php
  $value = 'something from somewhere';
  setcookie("TestCookie", $value); /* jian dan cookie she zhi */
  setcookie("TestCookie", $value, time()+3600); /* you xiao qi 1 ge xiao shi */
  setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".example.com", 1); /* you xiao mu lu /~rasmus, you xiao yu ming example.com ji qi suo you zi yu ming */
  ?>
  she zhi duo ge cookie bian liang : setcookie('var[a]','value'); yong shu zu lai biao shi bian liang , dan ta de xia biao bu yong yin hao . zhe yang jiu ke yi yong $_COOKIE[‘var’][‘a’] lai du qu gai COOKIE bian liang .
  1.1.2. shi yong header() she zhi cookie;
  header("Set-Cookie: name=$value[;path=$path[;domain=xxx.com[;...]]");
  hou mian de shen shu he shang mian lie chu setcookie han shu de shen shu yi yang .
  bi ru :
  $value = 'something from somewhere';
  header("Set-Cookie:name=$value");
  1.2 Cookie de du qu :
  zhi jie yong php nei zhi chao ji quan ju bian liang $_COOKIE jiu ke yi du qu liu lan qi duan de cookie.
  shang mian li zi zhong she zhi le cookie"TestCookie", xian zai wo men lai du qu :
  print $_COOKIE['TestCookie'];
  COOKIE shi bu shi bei shu chu le ?!
  1.3 shan chu cookie
  zhi xu ba you xiao shi jian she wei xiao yu dang qian shi jian , he ba zhi she zhi wei kong . li ru :
  setcookie("name","",time()-1);
  yong header() lei si .
  1.4 chang jian wen ti jie jue :
  1) yong setcookie() shi you cuo wu ti shi , ke neng shi yin wei tiao yong setcookie() qian mian you shu chu huo kong ge . ye ke neng ni de wen dang shi cong qi ta zi fu ji zhuan huan guo lai , wen dang hou mian ke neng dai you BOM qian ming ( jiu shi zai wen jian nei rong tian jia yi xie yin cang de BOM zi fu ). jie jue de ban fa jiu shi shi ni de wen dang bu chu xian zhe zhong qing kuang . huan you tong guo shi yong ob_start() han shu you ye neng chu li yi dian .
  2) $_COOKIE shou magic_quotes_gpc ying xiang , ke neng zi dong zhuan yi
  3) shi yong de shi hou , you bi yao ce shi yong hu shi fou zhi chi cookie
  <!--[if !supportLineBreakNewLine]-->
  1.5 cookie gong zuo ji li :
  you xie xue xi zhe bi jiao chong dong , mei xin si ba yuan li yan jiu , suo yi wo ba ta fang hou mian .
  a) fu wu qi tong guo sui zhe xiang ying fa song yi ge http de Set-Cookie tou , zai ke hu ji zhong she zhi yi ge cookie( duo ge cookie yao duo ge tou ).
  b) ke hu duan zi dong xiang fu wu qi duan fa song yi ge http de cookie tou , fu wu qi jie shou du qu .
  HTTP/1.x 200 OK
  X-Powered-By: PHP/5.2.1
  Set-Cookie: TestCookie=something from somewhere; path=/
  Expires: Thu, 19 Nov 2007 18:52:00 GMT
  Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
  Pragma: no-cache
  Content-type: text/html
  zhe yi xing shi xian le cookie gong neng , shou dao zhe xing hou
  Set-Cookie: TestCookie=something from somewhere; path=/
  liu lan qi jiang zai ke hu duan de ci pan shang chuang jian yi ge cookie wen jian , bing zai li mian xie ru :
  TestCookie=something from somewhere;
  /
  zhe yi xing jiu shi wo men yong setcookie('TestCookie','something from somewhere','/'); de jie guo . ye jiu shi yong header('Set-Cookie: TestCookie=something from somewhere; path=/'); de jie guo .
  <!--[endif]-->
  2. PHP de Session
  session shi yong guo qi shi jian she wei 0 de cookie, bing qie jiang yi ge cheng wei session ID de wei yi biao shi fu ( yi chang chuan zi fu chuan ), zai fu wu qi duan tong bu sheng cheng yi xie session wen jian ( ke yi zi ji ding yi session de bao cun lei xing ), yu yong hu ji guan lian qi lai .web ying yong cheng xu cun zhu yu zhe xie session xiang guan de shu ju , bing qie rang shu ju sui zhe yong hu zai ye mian zhi jian chuan di .
  fang wen wang zhan de lai ke hui bei fen pei yi ge wei yi de biao shi fu , ji suo wei de hui hua ID。 ta yao me cun fang zai ke hu duan de cookie, yao me jing you URL chuan di 。
  hui hua zhi chi yuan xu yong hu zhu ce ren yi shu mu de bian liang bing bao liu gei ge ge qing qiu shi yong 。 dang lai ke fang wen wang zhan shi ,PHP hui zi dong ( ru guo session.auto_start bei she wei 1) huo zai yong hu qing qiu shi ( you session_start() ming que tiao yong huo session_register() an zhong tiao yong ) jian cha qing qiu zhong shi fou fa song le te ding de hui hua ID。 ru guo shi , ze zhi qian bao cun de huan jing jiu bei chong jian 。
  2.1 sessionID de chuan song
  2.1.1 tong guo cookie chuan song sessin ID
   shi yong session_start() tiao yong session, fu wu qi duan zai sheng cheng session wen jian de tong shi , sheng cheng session ID ha xi zhi he mo ren zhi wei PHPSESSID de session name, bing xiang ke hu duan fa song bian liang wei ( mo ren de shi )PHPSESSID(session name), zhi wei yi ge 128 wei de ha xi zhi . fu wu qi duan jiang tong guo gai cookie yu ke hu duan jin xing jiao hu .
   session bian liang de zhi jing php nei bu xi lie hua hou bao cun zai fu wu qi ji qi shang de wen ben wen jian zhong , he ke hu duan de bian liang ming mo ren qing kuang xia wei PHPSESSID de coolie jin xing dui ying jiao hu .
   ji fu wu qi zi dong fa song le http tou :header('Set-Cookie: session_name()=session_id(); path=/');
  ji setcookie(session_name(),session_id());
   dang cong gai ye tiao zhuan dao de xin ye mian bing tiao yong session_start() hou ,PHP jiang jian cha yu gei ding ID xiang guan lian de fu wu qi duan cun zhu de session shu ju , ru guo mei zhao dao , ze xin jian yi ge shu ju ji .
  2.1.2 tong guo URL chuan song session ID
  zhi you zai yong hu jin zhi shi yong cookie de shi hou cai yong zhe zhong fang fa , yin wei liu lan qi cookie yi jing tong yong , wei an quan qi jian , ke bu yong gai fang fa .
  <a href="p.php?<?php print session_name() ?>=<?php print session_id() ?>">xxx</a>, ye ke yi tong guo POST lai chuan di session zhi .
  2.2 session ji ben yong fa shi li
  <?php
  // page1.php
  session_start();
  echo 'Welcome to page #1';
  /* chuang jian session bian liang bing gei session bian liang fu zhi */
  $_SESSION['favcolor'] = 'green';
  $_SESSION['animal'] = 'cat';
  $_SESSION['time'] = time();
  // ru guo ke hu duan shi yong cookie, ke zhi jie chuan di session dao page2.php
  echo '<br /><a href="page2.php">page 2</a>';
  // ru guo ke hu duan jin yong cookie
  echo '<br /><a href="page2.php?' . SID . '">page 2</a>';
  /*
  mo ren php5.2.1 xia ,SID zhi you zai cookie bei xie ru de tong shi cai hui you zhi , ru guo gai session
  dui ying de cookie yi jing cun zai , na me SID jiang wei ( wei ding yi ) kong
  */
  ?>
  <?php
  // page2.php
  session_start();
  print $_SESSION['animal']; // da yin chu dan ge session
  var_dump($_SESSION); // da yin chu page1.php chuan guo lai de session zhi
  ?>
  2.3 shi yong session han shu kong zhi ye mian huan cun .
   hen duo qing kuang xia , wo men yao que ding wo men de wang ye shi fou zai ke hu duan huan cun , huo yao she zhi huan cun de you xiao shi jian , bi ru wo men de wang ye shang you xie min gan nei rong bing qie yao deng lu cai neng cha kan , ru guo huan cun dao ben di le , ke yi zhi jie da kai ben di de huan cun jiu ke yi bu deng lu er liu lan dao wang ye le .
  shi yong session_cache_limiter('private'); ke yi kong zhi ye mian ke hu duan huan cun , bi xu zai session_start() zhi qian tiao yong .
  geng duo shen shu jian http://blog.chinaunix.net/u/27731/showart.php?id=258087 de ke hu duan huan cun kong zhi .
   kong zhi ke hu duan huan cun shi jian yong session_cache_expire(int); dan wei (s). ye yao zai session_start() qian tiao yong .
   zhe zhi shi shi yong session de qing kuang xia kong zhi huan cun de fang fa , wo men huan ke yi zai header() zhong kong zhi kong zhi ye mian de huan cun .
  2.4 shan chu session
  yao san bu shi xian .
  <?php
  session_destroy(); // di yi bu : shan chu fu wu qi duan session wen jian , zhe shi yong
  setcookie(session_name(),'',time()-3600); // di er bu : shan chu shi ji de session:
  $_SESSION = array(); // di san bu : shan chu $_SESSION quan ju bian liang shu zu
  ?>
  2.5 session zai PHP da xing web ying yong zhong de shi yong
  dui yu fang wen liang da de zhan dian , yong mo ren de session cun zhu fang shi bing bu shi he , mu qian zui you de fang fa shi yong shu ju ku cun qu session. zhe shi , han shu bool session_set_save_handler ( callback open, callback close, callback read, callback write, callback destroy, callback gc ) jiu shi ti gong gei wo men jie jue zhe ge wen ti de fang an .
  gai han shu shi yong de 6 ge han shu ru xia :
  1. bool open() yong lai da kai hui hua cun chu ji zhi ,
  2. bool close() guan bi hui hua cun chu cao zuo .
  3. mixde read() cong cun chu zhong zhuang zai session shu ju shi shi yong zhe ge han shu
  4. bool write() jiang gei ding session ID de suo you shu ju xie dao cun chu zhong
  5. bool destroy() po huai yu zhi ding de hui hua ID xiang guan lian de shu ju
  6. bool gc() dui cun chu xi tong zhong de shu ju jin xing la ji shou ji
  li zi jian php shou ce session_set_save_handler() han shu .
  ru guo yong lei lai chu li , yong
  session_set_save_handler(
   array('className','open'),
   array('className','close'),
   array('className','read'),
   array('className','write'),
   array('className','destroy'),
   array('className','gc'),
  )
  tiao yong className lei zhong de 6 ge jing tai fang fa .className ke yi huan dui xiang jiu bu yong tiao yong jing tai fang fa , dan shi yong jing tai cheng yuan bu yong sheng cheng dui xiang , xing neng geng hao .
  2.6 chang yong session han shu :
  bool session_start(void); chu shi hua session
  bool session_destroy(void): shan chu fu wu qi duan session guan lian wen jian 。
  string session_id() dang qian session de id
  string session_name() dang qian cun qu de session ming cheng , ye jiu shi ke hu duan bao cun session ID de cookie ming cheng . mo ren PHPSESSID。
  array session_get_cookie_params() yu zhe ge session xiang guan lian de session de xi jie .
  string session_cache_limiter() kong zhi shi yong session de ye mian de ke hu duan huan cun
  ini session_cache_expire() kong zhi ke hu duan huan cun shi jian
  bool session_destroy() shan chu fu wu qi duan bao cun session xin xi de wen jian
  void session_set_cookie_params ( int lifetime [, string path [, string domain [, bool secure [, bool httponly]]]] ) she zhi yu zhe ge session xiang guan lian de session de xi jie
  bool session_set_save_handler ( callback open, callback close, callback read, callback write, callback destroy, callback gc ) ding yi chu li session de han shu ,( bu shi shi yong mo ren de fang shi )
  bool session_regenerate_id([bool delete_old_session]) fen pei xin de session id
  2.7 session an quan wen ti
  gong ji zhe tong guo tou ru hen da de jing li chang shi huo de xian you yong hu de you xiao hui hua ID, you le hui hua id, ta men jiu you ke neng neng gou zai xi tong zhong yong you yu ci yong hu xiang tong de neng li .
  yin ci , wo men zhu yao jie jue de si lu shi xiao yan session ID de you xiao xing .
  <?php
  if(!isset($_SESSION['user_agent'])){
   $_SESSION['user_agent'] = $_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT'];
  }
  /* ru guo yong hu session ID shi wei zao */
  elseif ($_SESSION['user_agent'] != $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']) {
   session_regenerate_id();【原文】【汉音对照
 
 
 
 
 
 
 
 
 
日版宠物情人插曲《Winding Road》歌词

日版宠物情人2017的插曲,很带节奏感,日语的,女生唱的。 最后听见是在第8集的时候女主手割伤了,然后男主用嘴帮她吸了一下,插曲就出来了。 歌手:Def...

兄弟共妻,我成了他们夜里的美食

老钟家的两个儿子很特别,就是跟其他的人不太一样,魔一般的执着。兄弟俩都到了要结婚的年龄了,不管自家老爹怎么磨破嘴皮子,兄弟俩说不娶就不娶,老父母为兄弟两操碎了心...

如何磨出破洞牛仔裤?牛仔裤怎么剪破洞?

把牛仔裤磨出有线的破洞 1、具体工具就是磨脚石,下面垫一个硬物,然后用磨脚石一直磨一直磨,到把那块磨薄了,用手撕开就好了。出来的洞啊很自然的。需要猫须的话调几...

我就是扫描下图得到了敬业福和爱国福

先来看下敬业福和爱国福 今年春节,支付宝再次推出了“五福红包”活动,表示要“把欠大家的敬业福都还给大家”。 今天该活动正式启动,和去年一样,需要收集“五福”...

冰箱异味产生的原因和臭味去除的方法

有时候我们打开冰箱就会闻到一股异味,冰箱里的这种异味是因为一些物质发出的气味的混合体,闻起来让人恶心。 产生这些异味的主要原因有以下几点。 1、很多人有这种习...

 
 
1. PHP de COOKIE cookie shi yi zhong zai yuan cheng liu lan qi duan chu cun shu ju bing yi ci lai gen zong he shi bie yong hu de ji zhi 。 PHP zai http xie yi de tou xin xi li fa song cookie, yin ci setcookie() han shu bi xu zai qi ta xin xi bei shu chu dao liu lan qi qian tiao yong , zhe he dui header() han shu de xian zhi lei si 。 1.1 she zhi cookie: ke yi yong setcookie() huo setrawcookie() han shu lai she zhi cookie。 ye ke yi tong guo xiang ke hu duan zhi jie fa song http tou lai she zhi . 1.1.1 shi yong setcookie() han shu she zhi cookie: bool setcookie ( string name [, string value [, int expire [, string path [, string domain [, bool secure [, bool httponly]]]]]] ) name: cookie bian liang ming value: cookie bian liang de zhi expire: you xiao qi jie shu de shi jian , path: you xiao mu lu , domain: you xiao yu ming , ding ji yu wei yi secure: ru guo zhi wei 1, ze cookie zhi neng zai https lian jie shang you xiao , ru guo wei mo ren zhi 0, ze http he https dou ke yi . li zi : <?php $value = 'something from somewhere'; setcookie("TestCookie", $value); /* jian dan cookie she zhi */ setcookie("TestCookie", $value, time()+3600); /* you xiao qi 1 ge xiao shi */ setcookie("TestCookie", $value, time()+3600, "/~rasmus/", ".example.com", 1); /* you xiao mu lu /~rasmus, you xiao yu ming example.com ji qi suo you zi yu ming */ ?> she zhi duo ge cookie bian liang : setcookie('var[a]','value'); yong shu zu lai biao shi bian liang , dan ta de xia biao bu yong yin hao . zhe yang jiu ke yi yong $_COOKIE[‘var’][‘a’] lai du qu gai COOKIE bian liang . 1.1.2. shi yong header() she zhi cookie; header("Set-Cookie: name=$value[;path=$path[;domain=xxx.com[;...]]"); hou mian de shen shu he shang mian lie chu setcookie han shu de shen shu yi yang . bi ru : $value = 'something from somewhere'; header("Set-Cookie:name=$value"); 1.2 Cookie de du qu : zhi jie yong php nei zhi chao ji quan ju bian liang $_COOKIE jiu ke yi du qu liu lan qi duan de cookie. shang mian li zi zhong she zhi le cookie"TestCookie", xian zai wo men lai du qu : print $_COOKIE['TestCookie']; COOKIE shi bu shi bei shu chu le ?! 1.3 shan chu cookie zhi xu ba you xiao shi jian she wei xiao yu dang qian shi jian , he ba zhi she zhi wei kong . li ru : setcookie("name","",time()-1); yong header() lei si . 1.4 chang jian wen ti jie jue : 1) yong setcookie() shi you cuo wu ti shi , ke neng shi yin wei tiao yong setcookie() qian mian you shu chu huo kong ge . ye ke neng ni de wen dang shi cong qi ta zi fu ji zhuan huan guo lai , wen dang hou mian ke neng dai you BOM qian ming ( jiu shi zai wen jian nei rong tian jia yi xie yin cang de BOM zi fu ). jie jue de ban fa jiu shi shi ni de wen dang bu chu xian zhe zhong qing kuang . huan you tong guo shi yong ob_start() han shu you ye neng chu li yi dian . 2) $_COOKIE shou magic_quotes_gpc ying xiang , ke neng zi dong zhuan yi 3) shi yong de shi hou , you bi yao ce shi yong hu shi fou zhi chi cookie <!--[if !supportLineBreakNewLine]--> 1.5 cookie gong zuo ji li : you xie xue xi zhe bi jiao chong dong , mei xin si ba yuan li yan jiu , suo yi wo ba ta fang hou mian . a) fu wu qi tong guo sui zhe xiang ying fa song yi ge http de Set-Cookie tou , zai ke hu ji zhong she zhi yi ge cookie( duo ge cookie yao duo ge tou ). b) ke hu duan zi dong xiang fu wu qi duan fa song yi ge http de cookie tou , fu wu qi jie shou du qu . HTTP/1.x 200 OK X-Powered-By: PHP/5.2.1 Set-Cookie: TestCookie=something from somewhere; path=/ Expires: Thu, 19 Nov 2007 18:52:00 GMT Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0 Pragma: no-cache Content-type: text/html zhe yi xing shi xian le cookie gong neng , shou dao zhe xing hou Set-Cookie: TestCookie=something from somewhere; path=/ liu lan qi jiang zai ke hu duan de ci pan shang chuang jian yi ge cookie wen jian , bing zai li mian xie ru : TestCookie=something from somewhere; / zhe yi xing jiu shi wo men yong setcookie('TestCookie','something from somewhere','/'); de jie guo . ye jiu shi yong header('Set-Cookie: TestCookie=something from somewhere; path=/'); de jie guo . <!--[endif]--> 2. PHP de Session session shi yong guo qi shi jian she wei 0 de cookie, bing qie jiang yi ge cheng wei session ID de wei yi biao shi fu ( yi chang chuan zi fu chuan ), zai fu wu qi duan tong bu sheng cheng yi xie session wen jian ( ke yi zi ji ding yi session de bao cun lei xing ), yu yong hu ji guan lian qi lai .web ying yong cheng xu cun zhu yu zhe xie session xiang guan de shu ju , bing qie rang shu ju sui zhe yong hu zai ye mian zhi jian chuan di . fang wen wang zhan de lai ke hui bei fen pei yi ge wei yi de biao shi fu , ji suo wei de hui hua ID。 ta yao me cun fang zai ke hu duan de cookie, yao me jing you URL chuan di 。 hui hua zhi chi yuan xu yong hu zhu ce ren yi shu mu de bian liang bing bao liu gei ge ge qing qiu shi yong 。 dang lai ke fang wen wang zhan shi ,PHP hui zi dong ( ru guo session.auto_start bei she wei 1) huo zai yong hu qing qiu shi ( you session_start() ming que tiao yong huo session_register() an zhong tiao yong ) jian cha qing qiu zhong shi fou fa song le te ding de hui hua ID。 ru guo shi , ze zhi qian bao cun de huan jing jiu bei chong jian 。 2.1 sessionID de chuan song 2.1.1 tong guo cookie chuan song sessin ID shi yong session_start() tiao yong session, fu wu qi duan zai sheng cheng session wen jian de tong shi , sheng cheng session ID ha xi zhi he mo ren zhi wei PHPSESSID de session name, bing xiang ke hu duan fa song bian liang wei ( mo ren de shi )PHPSESSID(session name), zhi wei yi ge 128 wei de ha xi zhi . fu wu qi duan jiang tong guo gai cookie yu ke hu duan jin xing jiao hu . session bian liang de zhi jing php nei bu xi lie hua hou bao cun zai fu wu qi ji qi shang de wen ben wen jian zhong , he ke hu duan de bian liang ming mo ren qing kuang xia wei PHPSESSID de coolie jin xing dui ying jiao hu . ji fu wu qi zi dong fa song le http tou :header('Set-Cookie: session_name()=session_id(); path=/'); ji setcookie(session_name(),session_id()); dang cong gai ye tiao zhuan dao de xin ye mian bing tiao yong session_start() hou ,PHP jiang jian cha yu gei ding ID xiang guan lian de fu wu qi duan cun zhu de session shu ju , ru guo mei zhao dao , ze xin jian yi ge shu ju ji . 2.1.2 tong guo URL chuan song session ID zhi you zai yong hu jin zhi shi yong cookie de shi hou cai yong zhe zhong fang fa , yin wei liu lan qi cookie yi jing tong yong , wei an quan qi jian , ke bu yong gai fang fa . <a href="p.php?<?php print session_name() ?>=<?php print session_id() ?>">xxx</a>, ye ke yi tong guo POST lai chuan di session zhi . 2.2 session ji ben yong fa shi li <?php // page1.php session_start(); echo 'Welcome to page #1'; /* chuang jian session bian liang bing gei session bian liang fu zhi */ $_SESSION['favcolor'] = 'green'; $_SESSION['animal'] = 'cat'; $_SESSION['time'] = time(); // ru guo ke hu duan shi yong cookie, ke zhi jie chuan di session dao page2.php echo '<br /><a href="page2.php">page 2</a>'; // ru guo ke hu duan jin yong cookie echo '<br /><a href="page2.php?' . SID . '">page 2</a>'; /* mo ren php5.2.1 xia ,SID zhi you zai cookie bei xie ru de tong shi cai hui you zhi , ru guo gai session dui ying de cookie yi jing cun zai , na me SID jiang wei ( wei ding yi ) kong */ ?> <?php // page2.php session_start(); print $_SESSION['animal']; // da yin chu dan ge session var_dump($_SESSION); // da yin chu page1.php chuan guo lai de session zhi ?> 2.3 shi yong session han shu kong zhi ye mian huan cun . hen duo qing kuang xia , wo men yao que ding wo men de wang ye shi fou zai ke hu duan huan cun , huo yao she zhi huan cun de you xiao shi jian , bi ru wo men de wang ye shang you xie min gan nei rong bing qie yao deng lu cai neng cha kan , ru guo huan cun dao ben di le , ke yi zhi jie da kai ben di de huan cun jiu ke yi bu deng lu er liu lan dao wang ye le . shi yong session_cache_limiter('private'); ke yi kong zhi ye mian ke hu duan huan cun , bi xu zai session_start() zhi qian tiao yong . geng duo shen shu jian [url=http://blog.chinaunix.net/u/27731/showart.php?id=258087]http://blog.chinaunix.net/u/27731/showart.php?id=258087[/url] de ke hu duan huan cun kong zhi . kong zhi ke hu duan huan cun shi jian yong session_cache_expire(int); dan wei (s). ye yao zai session_start() qian tiao yong . zhe zhi shi shi yong session de qing kuang xia kong zhi huan cun de fang fa , wo men huan ke yi zai header() zhong kong zhi kong zhi ye mian de huan cun . 2.4 shan chu session yao san bu shi xian . <?php session_destroy(); // di yi bu : shan chu fu wu qi duan session wen jian , zhe shi yong setcookie(session_name(),'',time()-3600); // di er bu : shan chu shi ji de session: $_SESSION = array(); // di san bu : shan chu $_SESSION quan ju bian liang shu zu ?> 2.5 session zai PHP da xing web ying yong zhong de shi yong dui yu fang wen liang da de zhan dian , yong mo ren de session cun zhu fang shi bing bu shi he , mu qian zui you de fang fa shi yong shu ju ku cun qu session. zhe shi , han shu bool session_set_save_handler ( callback open, callback close, callback read, callback write, callback destroy, callback gc ) jiu shi ti gong gei wo men jie jue zhe ge wen ti de fang an . gai han shu shi yong de 6 ge han shu ru xia : 1. bool open() yong lai da kai hui hua cun chu ji zhi , 2. bool close() guan bi hui hua cun chu cao zuo . 3. mixde read() cong cun chu zhong zhuang zai session shu ju shi shi yong zhe ge han shu 4. bool write() jiang gei ding session ID de suo you shu ju xie dao cun chu zhong 5. bool destroy() po huai yu zhi ding de hui hua ID xiang guan lian de shu ju 6. bool gc() dui cun chu xi tong zhong de shu ju jin xing la ji shou ji li zi jian php shou ce session_set_save_handler() han shu . ru guo yong lei lai chu li , yong session_set_save_handler( array('className','open'), array('className','close'), array('className','read'), array('className','write'), array('className','destroy'), array('className','gc'), ) tiao yong className lei zhong de 6 ge jing tai fang fa .className ke yi huan dui xiang jiu bu yong tiao yong jing tai fang fa , dan shi yong jing tai cheng yuan bu yong sheng cheng dui xiang , xing neng geng hao . 2.6 chang yong session han shu : bool session_start(void); chu shi hua session bool session_destroy(void): shan chu fu wu qi duan session guan lian wen jian 。 string session_id() dang qian session de id string session_name() dang qian cun qu de session ming cheng , ye jiu shi ke hu duan bao cun session ID de cookie ming cheng . mo ren PHPSESSID。 array session_get_cookie_params() yu zhe ge session xiang guan lian de session de xi jie . string session_cache_limiter() kong zhi shi yong session de ye mian de ke hu duan huan cun ini session_cache_expire() kong zhi ke hu duan huan cun shi jian bool session_destroy() shan chu fu wu qi duan bao cun session xin xi de wen jian void session_set_cookie_params ( int lifetime [, string path [, string domain [, bool secure [, bool httponly]]]] ) she zhi yu zhe ge session xiang guan lian de session de xi jie bool session_set_save_handler ( callback open, callback close, callback read, callback write, callback destroy, callback gc ) ding yi chu li session de han shu ,( bu shi shi yong mo ren de fang shi ) bool session_regenerate_id([bool delete_old_session]) fen pei xin de session id 2.7 session an quan wen ti gong ji zhe tong guo tou ru hen da de jing li chang shi huo de xian you yong hu de you xiao hui hua ID, you le hui hua id, ta men jiu you ke neng neng gou zai xi tong zhong yong you yu ci yong hu xiang tong de neng li . yin ci , wo men zhu yao jie jue de si lu shi xiao yan session ID de you xiao xing . <?php if(!isset($_SESSION['user_agent'])){ $_SESSION['user_agent'] = $_SERVER['REMOTE_ADDR'].$_SERVER['HTTP_USER_AGENT']; } /* ru guo yong hu session ID shi wei zao */ elseif ($_SESSION['user_agent'] != $_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']) { session_regenerate_id();
󰈣󰈤
  免责声明:本文仅代表作者个人观点,与王朝网络无关。王朝网络登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述,其原创性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容、文字的真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
清凉一夏_清纯美丽
纯白色小礼服
靓丽可人儿_嘉嘉
我的女神_靓丽女生
主题摄影
贵州,让我欢喜,让我神伤。
莫干山
天平秋色
 
>>返回首页<<
 
 
 为你推荐
 
 
 
 转载本文
 UBB代码 HTML代码
复制到剪贴板...
 
 热帖排行
 
 
 
 
 
©2005- 王朝网络 版权所有