ÎÒÃÇÏÈ¿´¿´cookieÊÇʲô¶«¶«£¿
cookieÊÇþÎñÆ÷ÁoÔÚ¿Í»§¶ËµÄÓÃÓÚʶ±ðÓû§»oÕß´ae´¢Ò»Ð(C)Êý¾ÝµÄСÎļþ£¨×¢Òa£¬session´ae´¢ÔÚþÎñÆ÷¶Ë£¬ÕaÊÇÁ½ÕßµÄÇø±ðÖ®Ò»£(C)¡£ÎÒÃÇƽʱµÇ¼ijÃÅ»§Ê±£¬»aÓÐÑ¡Ïi¡°ÊÇñ±£´aeµÇ¼¡±»oÕß¡°Ï´Î×Ô¶¯µÇ¼¡±£¬µ±ÎÒÃǹ´Ñ¡ÁËÖ®ºo£¬þÎñÆ÷¾Í»aÔÚÎÒÃǵÄa¯ÀÀÆ÷´´½¨cookieÎļþÀ´±£´aeÎÒÃǵÄÐÅÏ¢¡£Ã¿µ±¼ÆËa»uͨ¹ýa¯ÀÀÆ÷ÇeÇoÒ³Ãaeʱ£¬Ëu»aͬʱ*¢ËÍcookie¡£Í¨¹ýPHP£¬¿ÉÒÔ´´½¨²¢È¡»ØcookieµÄÖµ¡£cookieÔÚwebÖÐÊǺÜÖØÒªµÄ½ÇÉ«£¬ÔçÔÚÍø¾°a¯ÀÀÆ÷µÄʱºo¾Í²uÉuÁËcookie¡£cookie¾³£±»ÓÃÓÚÓû§Ñe֤ϵͳ¡£
1.´´½¨cookie
º¯Êýsetcookie()¿ÉÒÔÔÚPHPÖÐÉu³Écookie¡£ÓÉÓÚcookieÊÇHTTPͱe²¿ÖµÄÄÚÈÝ£¬Òo´Ë±ØÐeÔÚÊa³oÈκÎÊý¾Ý֮ǰµ÷ÓÃsetcookie()£¬Õa¸oÏÞÖƺÍheader()ÀaËÆ£¬¶¨Òa£º
bool setcookie( string name[,string value][,int expire][,string path][,string domain][,bool secure][,bool httponly])
ºÃ¶a²ÎÊý°¡£¡¦²(¡Ñ¨Œ¡Ñ"a ²»¼±£¬ÈÃÎÒÃÇ¿´¿´¸÷¸o²ÎÊýµÄ×÷Óãº
name : ±ØÑ¡£¬±iʾcookieµÄÃu×Ö¡£
value £º ¿ÉÑ¡£¬±iʾcookieÖµ£¬´ae´¢ÔÚ¿Í»§¶Ë£¬µ±Îª¿Õʱ£¬±iʾ³Ïu¿Í»§¶ËÖиÃcookieµÄ×ÊÁÏ£¨ÕaÑu¿ÉÒÔɾ³ýcookie£(C)¡£
expire £º ¿ÉÑ¡£¬±iʾcookieµÄÓÐЧ½Øֹʱ¼a£¬Ò²¾ÍÊǹýÆÚʱ¼a£¬Èç¹uûÓÐÖ¸¶¨»oÕßÖ¸¶¨Îª0£¬ÄÇôͨ³£ÊÇÔڹرÕa¯ÀÀÆ÷ʱʧЧ¡£
path £º ¿ÉÑ¡£¬cookieÓÐЧ¾¶¡£
domain £º ¿ÉÑ¡£¬cookieÓÐЧÓoÃu¡£
secure £º ±iʾÔÚHTTPSµÄ°²È«´«Êaʱ²ÅÓÐЧ¡£
ʵÀý(½¨Á¢Ò»¸oÃu×ÖΪtest£¬ÖµÎªChinaµÄcookie)£º
<?php
setcookie("test",China");
?>
ʹÓÃsetcookie()¸øµÄÖµÖ»ÄÜÊÇÊý×Ö»oÕß×Ö*u´®£¬²»ÄÜÊÇÆaËuµÄ¸´ÔÓ½a¹¹¡£
2.»ñÈ¡cookie
´´½¨cookieºo£¬¾Í¿ÉÒÔʹÓÃÔ¤¶¨Òa±aÁ¿$_COOKIEÀ´»ñÈ¡cookie¡£²»¹ý£¬Ö»ÄÜÔÚÆaËuÒ³Ãae»ñÈ¡cookie£¬ÒoΪÔÚphpÖУ¬±»ÉeÖõÄcookie²»»aÔÚ±¾Ò³ÃaeÉuЧ£¬³ý*ǸÃÒ³Ãae±»Ë¢Ð¡£
ʵÀý£º
<?php
setcookie("test","China");
echo "cookie is ".$_COOKIE["test"];
?>
ÕaÀiÖ®ËuÒÔҪˢÐÂÒ³Ãae£¬ÊÇÒoΪcookieµÄÖµ²»»aÔÚµ÷ÓÃsetcookie()Ö®ºoÁ¢¼´´ae´¢ÔÚ C OOKIE±aÁ¿ÖУ¬¶øÊÇËae×ÅhttpÇeÇo±»¢ËÍÖÁþÎñÆ÷£¬ÕaʱºocookieµÄÖµ²Å»a³oÏÖÔÚ COOKIE±aÁ¿ÖУ¬¶øÊÇËae×ÅhttpÇeÇo±»¢ËÍÖÁþÎñÆ÷£¬ÕaʱºocookieµÄÖµ²Å»a³oÏÖÔÚ_COOKIEÖС££¨²(C)¿ÍÔ°¶ÔÓÚdollar*u²»Ö§³Öô¡£¡£¡£°¡°¡°¡£(C)
3.cookieµÄÓÐЧÆÚ
cookieÓÐÉuÃuÖÜÆÚ£¬Ò²¾ÍÊÇcookie´aeÔÚµÄÓÐЧʱ¼a¡£¿ÉÒÔÉeÖõÚÈý¸o²ÎÊýÀ´ÉeÖÃÓÐЧʱ¼a¡£
ʵÀý£¨ÉeÖÃcookieÓÐЧʱ¼aµÄ¼¸ÖÖ*½Ê½£(C)£º
setcookie("cookie_one","A",time()+60*60); //cookieÔÚһСʱºoʧЧ
setcookie("cookie_two","B",time()+60*60*24); //cookieÔÚÒ»ÌiºoʧЧ
setcookie("cookie_three","C",mktime(23,53,19,10,09,2020)); //cookieÔÚ2020Äe10ÔÂ9ÈÕ23ʱ53*Ö19ÃeʧЧ
setcookie("cookie_four","D"); //¹Ø±Õa¯ÀÀÆ÷ºocookieʧЧ
*4.cookieµÄÓÐЧ¾¶
*cookieÖеľ¶ÓÃÀ´¿ØÖÆÉeÖõÄcookieÔÚÄĸo¾¶ÏÂÓÐЧ£¬Ä¬ÈÏΪ'/'£¬ÔÚËuÓо¶Ï¶¼ÓÐЧ£¬Ò²¾ÍÊÇÔÚÕu¸oþÎñÆ÷ÓoÃu϶¼ÓÐЧ£¬µ±Ée¶¨ÁËÆaËu¾¶Ö®ºo£¬ÔoÖ»ÔÚÉe¶¨µÄ¾¶ÒÔ¼°×Ó¾¶ÏÂÓÐЧ£¬ÀýÈ磺
setcookie('test', time(), 0, '/path');
ÉÏÃaeµÄÉeÖûaʹtestÔÚ/pathÒÔ¼°×ÓÂ*¾¶/path/abc϶¼ÓÐЧ£¬µ«ÊÇÔÚ¸uĿ¼Ï¾ͶÁÈ¡²»µ½testµÄcookieÖµ¡£
Ò»°aÇe¿oÏ£¬´o¶aÊÇʹÓÃËuÓо¶µÄ£¬Ö»ÓÐÔÚ¼«ÉÙÊýÓÐÌØÊaÐeÇoµÄʱºo£¬»aÉeÖþ¶£¬ÕaÖÖÇe¿oÏÂÖ»ÔÚÖ¸¶¨µÄÂ*¾¶ÖвŻa´«µÝcookieÖµ£¬¿ÉÒÔ½ÚÊ¡Êý¾ÝµÄ´«Êa£¬ÔoÇ¿°²È«ÐÔÒÔ¼°Ìa¸ßÐÔÄÜ¡£
5.ɾ³ýcookie
ɾ³ýcookie±È½Ï¼oµ¥£¬Ò²ÊÇͨ¹ýsetcookie()À´ÊµÏֵģ¨²»ÒªÊ¹ÓÃunset()!!!£(C)ÏÂÃaeµÄ´uÂe¾ÍÊǸo¼oµ¥Àý×Ó£ºsetcookie("test","");
ͨ¹ý½«µÚ¶þ¸o²ÎÊýÉeΪ¿ÕÀ´´iµ½É¾³ýcookieµÄÄ¿µÄ¡£Èç¹uÉeÖÃcookieʱ£¬ÎªcookieÌa¹(C)ÁËÌض¨µÄÖµ£¬ÄÇôÔÚɾ³ýcookieʱ£¬ÈÔÈ»ÐeÒªÌa¹(C)ÕaÐ(C)²ÎÊý£¬ÒÔ±aPHP¿ÉÒÔÕýÈ*µØɾ³ýcookie¡£
ÒÔÉϾÍÊDZ¾ÎĵÄÈ«²¿ÄÚÈÝ£¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu£¬Ò²Ï£Íu´o¼Ò¶a¶aÖ§³Ö½Å±¾Ö®¼Ò¡£