Èôo¼Ò¶ÔCookieºÍSessionÓÐÒ»¸o¸uÉiÈeµÄÁ˽a£¬²¢¶Ô×Ô¼ºµÄ¿ª*¢¹¤×÷ÖÐÁe»iÔËÓôøÀ´Æoʾ¡£
Ò»¡¢cookie»uÖÆ
CookiesÊÇþÎñÆ÷ÔÚ±¾µØ»uÆ÷ÉÏ´ae´¢µÄС¶ÎÎı¾²¢Ëaeÿһ¸oÇeÇo¢ËÍÖÁͬһ¸oþÎñÆ÷¡£IETF RFC 2965 HTTP State Management Mechanism ÊÇͨÓÃcookie¹ae¶¡£ÍøÂçþÎñÆ÷ÓÃHTTPÍÏo¿Í»§¶Ë¢ËÍcookies£¬ÔÚ¿Í»§Öնˣ¬a¯ÀÀÆ÷½aÎoÕaÐ(C)cookies²¢½«ËuÃDZ£´aeΪһ¸o±¾µØÎļþ£¬Ëu»a×Ô¶¯½«Í¬Ò»þÎñÆ÷µÄÈκÎÇeÇo¸¿ÉÏÕaÐ(C)cookies ¡£
¾ßÌaÀ´Ëµcookie»uÖƲÉÓõÄÊÇÔÚ¿Í»§¶Ë±£³Ö״̬µÄ½°¸¡£ËuÊÇÔÚÓû§¶ËµÄ»a»°×´Ì¬µÄ´aeÖu»uÖÆ£¬ËuÐeÒªÓû§´o¿ª¿Í»§¶ËµÄcookieÖ§³Ö¡£cookieµÄ×÷ÓþÍÊÇΪÁ˽a¾oHTTPÐÒeÎÞ״̬µÄȱÏÝËu×÷µÄŬÁ¦¡£
ÕýͳµÄcookieÖ¢ÊÇͨ¹ýÀ(C)Õ¹HTTPÐÒeÀ´ÊµÏֵģ¬þÎñÆ÷ͨ¹ýÔÚHTTPµÄÏiÓ¦ÍÖмÓÉÏÒ»ÐÐÌØÊaµÄָʾÒÔÌaʾa¯ÀÀÆ÷°´ÕÕָʾÉu³ÉÏaÓ¦µÄcookie¡£È»¶ø´¿´aµÄ¿Í»§¶Ë½Å±¾ÈçJavaScriptÒ²¿ÉÒÔÉu³Écookie¡£¶øcookieµÄʹÓÃÊÇÓÉa¯ÀÀÆ÷°´ÕÕÒ»¶¨µÄÔÔoÔÚºǫ×Ô¶¯¢Ë͸øþÎñÆ÷µÄ¡£a¯ÀÀÆ÷¼i²eËuÓдae´¢µÄcookie£¬Èç¹uij¸ocookieËuÉuÃ÷µÄ×÷ÓöΧ´oÓÚµÈÓÚ½«ÒªÇeÇoµÄ×ÊÔ´ËuÔÚµÄλÖã¬Ôo°Ñ¸Ãcookie¸½ÔÚÇeÇo×ÊÔ´µÄHTTPÇeÇoÍÉÏ¢Ë͸ø*þÎñÆ÷¡£
cookieµÄÄÚÈÝÖ÷Òª°uÀ¨£º*Ãu×Ö£¬Öµ£¬¹ýÆÚʱ¼a£¬Â¾¶ºÍÓo*¡£Â¾¶ÓeÓoÒ»Æð¹¹³ÉcookieµÄ×÷ÓöΧ¡£Èo²»ÉeÖùýÆÚʱ¼a£¬Ôo±iʾÕa¸ocookieµÄÉuÃuÆÚΪa¯ÀÀÆ÷»a»°ÆÚ¼a£¬¹Ø±Õa¯ÀÀÆ÷´°¿Ú£¬cookie¾ÍÏuʧ¡£ÕaÖÖÉuÃuÆÚΪa¯ÀÀÆ÷»a»°ÆÚµÄcookie±»³ÆΪ»a»°cookie¡£»a»°cookieÒ»°a²»´ae´¢ÔÚÓ²ÅÌÉ϶øÊDZ£´aeÔÚÄÚ´aeÀi£¬µ±È»ÕaÖÖÐÐΪ²¢²»Êǹae¶¹ae¶¨µÄ¡£ÈoÉeÖÃÁ˹ýÆÚʱ¼a£¬a¯ÀÀÆ÷¾Í»a°Ñcookie±£´aeµ½Ó²ÅÌÉÏ£¬¹Ø±ÕºoÔٴδo¿ªa¯ÀÀÆ÷£¬ÕaÐ(C)cookieÈÔÈ»ÓÐЧֱµ½³¬¹ýÉe¶¨µÄ¹ýÆÚʱ¼a¡£´ae´¢ÔÚÓ²ÅÌÉϵÄcookie¿ÉÒÔÔÚ²»Í¬µÄa¯ÀÀÆ÷½ø³Ì¼a¹²Ïi£¬±ÈÈçÁ½¸oIE´°¿Ú¡£¶ø¶ÔÓÚ±£´aeÔÚÄÚ´aeÀiµÄcookie£¬²»Í¬µÄa¯ÀÀÆ÷Óв»Í¬µÄ´¦Ài*½Ê½¡£
¶øsession»uÖƲÉÓõÄÊÇÒ»ÖÖÔÚþÎñÆ÷¶Ë±£³Ö״̬µÄ½a¾o½°¸¡£Í¬Ê±ÎÒÃÇÒ²¿´µ½£¬ÓÉÓÚ²ÉÓÃþÎñÆ÷¶Ë±£³Ö״̬µÄ½°¸ÔÚ¿Í»§¶ËÒ²ÐeÒª±£´aeÒ»¸o±eʶ£¬ËuÒÔsession»uÖÆ¿ÉÄÜÐeÒª½eÖuÓÚcookie»uÖÆÀ´´iµ½±£´ae±eʶµÄÄ¿µÄ¡£¶øsessionÌa¹(C)Á˽±a¹ÜÀiÈ«¾Ö±aÁ¿µÄ½Ê½ ¡£
sessionÊÇÕe¶Ôÿһ¸oÓû§µÄ£¬±aÁ¿µÄÖµ±£´aeÔÚþÎñÆ÷ÉÏ£¬ÓÃÒ»¸osessionIDÀ´ÇøÖÊÇÄĸoÓû§session±aÁ¿,Õa¸oÖµÊÇͨ¹ýÓû§µÄa¯ÀÀÆ÷ÔÚÃÎʵÄʱºoµ»Ø¸øþÎñÆ÷£¬µ±¿Í»§½uÓÃcookieʱ£¬Õa¸oÖµÒ²¿ÉÄÜÉeÖÃΪÓÉgetÀ´µ»Ø¸ø*þÎñÆ÷¡£
¾Í°²È«ÐÔÀ´Ëµ£ºµ±ÄaÃÎÊÒ»¸oʹÓÃsession µÄÕ¾µa£¬Í¬Ê±ÔÚ×Ô¼º»u×ÓÉϽ¨Á¢Ò»¸ocookie£¬½¨ÒeÔÚþÎñÆ÷¶ËµÄsession»uÖƸu°²È«Ð(C)£¬ÒoΪËu²»»aÈÎÒa¶ÁÈ¡¿Í»§´ae´¢µÄÐÅÏ¢¡£
¶þ¡¢session»uÖÆ
session»uÖÆÊÇÒ»ÖÖþÎñÆ÷¶ËµÄ»uÖÆ£¬þÎñÆ÷ʹÓÃÒ»ÖÖÀaËÆÓÚÉ¢ÁбiµÄ½a¹¹£¨Ò²¿ÉÄܾÍÊÇʹÓÃÉ¢Áбi£(C)À´±£´aeÐÅÏ¢¡£
µ±³ÌÐoÐeҪΪij¸o¿Í»§¶ËµÄÇeÇo´´½¨Ò»¸osessionʱ£¬þÎñÆ÷Ê×Ïȼi²eÕa¸o¿Í»§¶ËµÄÇeÇoÀiÊÇñÒÑ°uº¬ÁËÒ»¸osession±eʶ£¨³ÆΪsession id£(C)£¬Èç¹uÒÑ°uº¬Ôo˵Ã÷ÒÔÇ°ÒѾΪ´Ë¿Í»§¶Ë´´½¨¹ýsession£¬þÎñÆ÷¾Í°´ÕÕsession id°ÑÕa¸osession¼iË÷³oÀ´Ê¹Ó㨼iË÷²»µ½£¬»aн¨Ò»¸o£(C)£¬Èç¹u¿Í»§¶ËÇeÇo²»°uº¬session id£¬ÔoΪ´Ë¿Í»§¶Ë´´½¨Ò»¸osession²¢ÇÒÉu³ÉÒ»¸oÓe´ËsessionÏa¹ØÁªµÄsession id£¬session idµÄÖµÓ¦¸ÃÊÇÒ»¸o¼È²»»aÖظ´£¬ÓÖ²»ÈÝÒ×±»ÕÒµ½¹aeÂÉÒÔÂÔiµÄ×Öu´®£¬Õa¸osession id½«±»ÔÚ±¾´ÎÏiÓ¦Öе»Ø¸ø¿Í»§¶Ë±£´ae¡£
±£´aeÕa¸osession idµÄ½Ê½¿ÉÒÔ²ÉÓÃcookie£¬ÕaÑuÔÚ½»»¥¹ý³ÌÖÐa¯ÀÀÆ÷¿ÉÒÔ×Ô¶¯µÄ°´ÕÕ¹aeÔo°ÑÕa¸o±eʶ¢»Ó¸øþÎñÆ÷¡£Ò»°aÕa¸ocookieµÄÃu×Ö¶¼ÊÇÀaËÆÓÚSEEESIONID¡£µ«cookie¿ÉÒÔ±»ÈËΪµÄ½uÖ¹£¬Ôo±ØÐeÓÐÆaËu»uÖÆÒÔ±aÔÚcookie±»½uֹʱÈÔÈ»Äܹ»°Ñsession id´«µÝ»ØþÎñÆ÷¡£
¾³£±»Ê¹ÓõÄÒ»ÖÖ¼¼Êo½Ð×oURLÖØд£¬¾ÍÊÇ°Ñsession idÖ±½Ó¸½¼ÓÔÚURL¾¶µÄºoÃae¡£»¹ÓÐÒ»ÖÖ¼¼Êo½Ð×o±iµ¥Òþ²Ø×ֶΡ£¾ÍÊÇþÎñÆ÷»a×Ô¶¯Ð޸ıiµ¥£¬Ìi¼ÓÒ»¸oÒþ²Ø×ֶΣ¬ÒÔ±aÔÚ±iµ¥Ìa½»Ê±Äܹ»°Ñsession id´«µÝ»Ø*þÎñÆ÷¡£
CookieÓeSession¶¼Äܹ»½øÐлa»°¸u×Ù£¬µ«ÊÇÍe³ÉµÄÔÀi²»Ì«Ò»Ñu¡£ÆÕͨ״¿o϶þÕß¾uÄܹ»Âu×aÐeÇo£¬µ«ÓÐʱֲ»Äܹ»ÔËÓÃCookie£¬ÓÐʱֲ»Äܹ»ÔËÓÃSession¡£
ÏÂÃae¾¹ý±ÈÄa²uÃ÷¶þÕßµÄÌØÐÔÒÔ¼°ÊÊÓõij¡Ëu¡£
*1 .´aeÈ¡½Ê½µÄ²»Í¬**
CookieÖÐÖ»Äܱ£¹ÜASCII×Öu´®£¬¼ÙÈçÐeÇo´aeÈ¡Unicode×Öu»oÕ߶þ½øÖÆÊý¾Ý£¬ÐeÇoÏȽøÐбaÂe¡£CookieÖÐÒ²²»ÄÜÖ±½Ó´aeÈ¡Java¶ÔÏo¡£ÈoÒª´ae´¢ÂÔ΢¸´ÔÓµÄÐÅÏ¢£¬ÔËÓÃCookieÊDZÈÄa¼eÄѵġ£
¶øSessionÖÐÄܹ»´aeÈ¡ÈκÎÀaÐ͵ÄÊý¾Ý£¬°uÀ¨¶ø²»ÏÞÓÚString¡¢Integer¡¢List¡¢MapµÈ¡£SessionÖÐÒ²Äܹ»Ö±½Ó±£¹ÜJava BeanÄËÖÁÈκÎJavaÀa£¬¶ÔÏoµÈ£¬ÔËÓÃÆðÀ´Ê®*Ö±aµ±¡£Äܹ»°ÑSession¿´×oÊÇÒ»¸oJavaÈÝÆ÷Àa¡£
2 .Òþ˽²ßÂԵIJ»Í¬
Cookie´ae´¢ÔÚ¿Í»§¶ËÔĶÁÆ÷ÖУ¬¶Ô¿Í»§¶ËÊǿɼuµÄ£¬¿Í»§¶ËµÄÒ»Ð(C)³ÌÐo¿ÉÄÜ»a¿u̽¡¢¸´ÖÆÒÔÖÁÐÞÕýCookieÖеÄÄÚÈÝ¡£¶øSession´ae´¢ÔÚþÎñÆ÷ÉÏ£¬¶Ô¿Í»§¶ËÊÇ͸Ã÷µÄ£¬²»´aeÔÚÃo¸ÐÐÅϢ鶵ÄçÏÕ¡£
¼ÙÈçÑ¡ÓÃCookie£¬±È½ÏºÃµÄ½¨ÊÇ£¬Ão¸ÐµÄÐÅÏ¢ÈçÕ˺ÅÃÜÂeµÈ¾¡Á¿²»ÒªÐ´µ½CookieÖС£×iºÃÊÇÏñGoogle¡¢BaiduÄÇÑu½«CookieÐÅÏ¢¼ÓÃÜ£¬Ìa½»µ½þÎñÆ÷ºoÔÙ½øÐнaÃÜ£¬±£Ö¤CookieÖеÄÐÅÏ¢Ö»Òª±¾ÈËÄܶÁµÃ¶®¡£¶ø¼ÙÈçÑ¡ÔñSession¾ÍʡʶaÁË£¬´ÕýÊÇÅÔÚþÎñÆ÷ÉÏ£¬SessionÀiÈκÎÒþ˽¶¼Äܹ»ÓÐЧµÄ±£»¤¡£
3.ÓÐЧÆÚÉϵIJ»Í¬
ʹÓùýGoogleµÄÈ˶¼ÏþµÃ£¬¼ÙÈçµÇ¼¹ýGoogle£¬ÔoGoogleµÄµÇ¼ÐÅÏ¢³¤ÆÚÓÐЧ¡£Óû§²»ÓÃÿ´Î*ÃÎʶ¼ÖØеǼ£¬Google»a³Ö¾ÃµØ¼ÇÔظÃÓû§µÄµÇ¼ÐÅÏ¢¡£Òªµ½´iÕaÖÖЧ¹u£¬ÔËÓÃCookie»aÊDZȽϺõÄÑ¡Ôñ¡£Ö»ÐeÒªÉeÖÃCookieµÄ¹ýÆÚʱ¼aÊoÐÔΪһ¸oºÜ´oºÜ´oµÄÊý×Ö¡£
ÓÉÓÚSessionÒÀÀµÓÚÃuΪJSESSIONIDµÄCookie£¬¶øCookie JSESSIONIDµÄ¹ýÆÚʱ¼aĬÐiΪ¨C1£¬Ö»Ðe¹Ø±ÕÁËÔĶÁÆ÷¸ÃSession¾Í»aʧЧ£¬Òo¶øSession²»ÄÜÍe³ÉÐÅÏ¢ÓÀÊÀÓÐЧµÄЧ¹u¡£ÔËÓÃURLµØÖÖØдҲ²»ÄÜÍe³É¡£¶øÇÒ¼ÙÈçÉeÖÃSessionµÄ³¬Ê±Ê±¼a¹ý³¤£¬þÎñÆ÷ÀۼƵÄSession¾Í»aÔ½¶a£¬Ô½ÈÝÒ×ÕÐÖÂÄÚ´aeÒç³o¡£
*4.þÎñÆ÷ѹÁ¦µÄ²»Í¬**
SessionÊDZ£¹ÜÔÚþÎñÆ÷¶ËµÄ£¬Ã¿¸oÓû§¶¼»a²uÉuÒ»¸oSession¡£¼ÙÈç²¢¢ÃÎʵÄÓû§Ê®Ö¶a£¬»a²uÉuʮֶaµÄSession£¬ºÄÑ´oÁ¿µÄÄÚ´ae¡£Òo¶øÏñGoogle¡¢Baidu¡¢SinaÕaÑu²¢¢ÃÎÊÁ¿¼«¸ßµÄÍøÕ¾£¬ÊDz»Ì«¿ÉÄÜÔËÓÃSessionÀ´×*×Ù¿Í»§»a»°µÄ¡£
¶øCookie±£¹ÜÔÚ¿Í»§¶Ë£¬²»Õ¼ÓÃþÎñÆ÷×ÊÔ´¡£¼ÙÈç²¢¢ÔĶÁµÄÓû§Ê®*Ö¶a£¬CookieÊǺܺõÄÑ¡Ôñ¡£¹ØÓÚGoogle¡¢Baidu¡¢SinaÀ´Ëµ£¬Cookie»oÐiÊÇΨһµÄÑ¡Ôñ¡£
5 .a¯ÀÀÆ÷Ö§³ÖµÄ²»Í¬
CookieÊÇÐeÒª¿Í»§¶Ëa¯ÀÀÆ÷Ö§³ÖµÄ¡£¼ÙÈç¿Í»§¶Ë½uÓÃÁËCookie£¬»oÕß²»Ö§³ÖCookie£¬Ôo»a»°¸u×Ù»aʧЧ¡£¹ØÓÚWAPÉϵÄÓ¦Ó㬳£¹aeµÄCookie¾ÍÅɲ»ÉÏÓó¡ÁË¡£
¼ÙÈç¿Í»§¶Ëa¯ÀÀÆ÷²»Ö§³ÖCookie£¬ÐeÒªÔËÓÃSessionÒÔ¼°URLµØÖÖØд¡£ÐeҪעÒaµÄÊÇÒ»ÇеÄÓõ½Session³ÌÐoµÄURL¶¼Òª½øÐÐURLµØÖÖØд£¬ñÔoSession»a»°¸u×Ù»¹»aʧЧ¡£¹ØÓÚWAPÓ¦ÓÃÀ´Ëµ£¬Session+URLµØÖÖØд»oÐiÊÇËuΨһµÄÑ¡Ôñ¡£
¼ÙÈç¿Í»§¶ËÖ§³ÖCookie£¬ÔoCookie¼ÈÄܹ»ÉeΪ±¾a¯ÀÀÆ÷´°¿ÚÒÔ¼°×Ó´°¿ÚÄÚÓÐЧ£¨°Ñ¹ýÆÚʱ¼aÉeΪ¨C1£(C)£¬Ò²Äܹ»ÉeΪһÇÐÔĶÁÆ÷´°¿ÚÄÚÓÐЧ£¨°Ñ¹ýÆÚʱ¼aÉeΪij¸o´oÓÚ0µÄÕuÊý£(C)¡£µ«SessionÖ»ÄÜÔÚ±¾ÔĶÁÆ÷´°¿ÚÒÔ¼°Æa×Ó´°¿ÚÄÚÓÐЧ¡£¼ÙÈçÁ½¸oa¯ÀÀÆ÷´°¿Ú»¥²»Ïa¸É£¬ËuÃǽ«ÔËÓÃÁ½¸o²»Í¬µÄSession¡££¨IE8ϲ»Í¬´°¿ÚSessionÏa¸É£(C)
6.¿çÓoÖ§³ÖÉϵIJ»Í¬
CookieÖ§³Ö¿çÓoÃuÃÎÊ£¬ÀýÈ罫domainÊoÐÔÉeÖÃΪ¡°.biaodianfu.com¡±£¬ÔoÒÔ¡°.biaodianfu.com¡±Îªºo׺µÄÒ»ÇÐÓoÃu¾uÄܹ»ÃÎʸÃCookie¡£¿çÓoÃuCookieÈç½ñ±»ÆÕ±eÓÃÔÚÍøÂçÖУ¬ÀýÈçGoogle¡¢Baidu¡¢SinaµÈ¡£¶øSessionÔo²»»aÖ§³Ö¿çÓoÃu*ÃÎÊ¡£Session½oÔÚËuËuÔÚµÄÓoÃuÄÚÓÐЧ¡£
½oÔËÓÃCookie»oÕß½oÔËÓÃSession¿ÉÄÜÍe³É²»ÁËÀiÏeµÄЧ¹u¡£ÕaʱӦ¸Ã³¢ÊÔÒ»ÏÂͬʱÔËÓÃCookieÓeSession¡£CookieÓeSessionµÄ´iÅaÔËÓÃÔÚʵ¼uÏiÄ¿ÖлaÍe³ÉºÜ¶aÒaÏe²»µ½µÄЧ¹u¡£
ÒÔÉϾÍÊÇÕe¶ÔphpÖÐCookieÓeSession½øÐеÄÇø*ֱȽϣ¬Ï£Íu¶Ô´o¼ÒµÄѧϰÓÐËu°iÖu¡£