laravel session ɥʧ
laravelÊÇÒ»¸ö¹ãÊܽӴýµÄphp¿ò¼Ü£¬ËüºÜºÃµØ½â¾öÁËweb¿ª·¢ÖеÄÐí¶àÎÊÌ⡣Ȼ¶ø£¬ÓÐʱ¼äÄú¿ÉÄÜ»áÓöµ½Ò»¸öºÜÑá¶ñµÄÎÊÌ⡪¡ªlaravel»áɥʧsession¡£±¾ÎĽ«ÏêϸÏÈÈÝlaravel sessionɥʧµÄÔµ¹ÊÔÓÉÏ¢Õù¾ö¼Æ»®¡£
Ò»¡¢Ê²Ã´ÊÇLaravel Session£¿
SessionÊÇWeb¿ª·¢ÖеÄÒ»ÖÖ»úÖÆ£¬ÔÊÐíЧÀÍÆ÷ÔÚ¶à¸öHTTPÇëÇóÖ®¼äÉúÑÄÓû§Êý¾Ý¡£LaravelÌṩÁËÒ»¸öÀû±ãµÄsession×é¼þ£¬¿ÉÒÔÇáËÉ´æ´¢ºÍ»á¼ûsessionÊý¾Ý¡£
¶þ¡¢ÎªÊ²Ã´»á·ºÆðSessionɥʧ£¿
Ê×ÏÈ£¬ÎÒÃÇÐèÒªÖªµÀLaravel SessionÊÇͨ¹ýcookieÀ´ÊµÏֵġ£µ±Óû§¾ÙÐеÚÒ»´ÎÇëÇóʱ£¬ÔÚHTTPÏìӦͷÖлáÉèÖÃÒ»¸öÃûΪXSRF-TOKENµÄcookie¡£Ã¿´ÎÌá½»±íµ¥Ê±£¬Laravel¶¼»á¼ì²éXSRF-TOKEN cookieÊÇ·ñÆ¥Åä¡£ÈôÊÇÆ¥Å䣬Laravel¾Í»á¼ÌÐøʹÓÃsessionºÍÆäËûcookies¡£
ÈôÊÇXSRF-TOKEN cookie²»Æ¥Å䣬Laravel¾Í»áÖÐÖ¹¾ç±¾µÄÖ´ÐУ¬Õâ¾ÍÊÇSessionɥʧµÄÖ÷ÒªÔµ¹ÊÔÓÉ¡£¿ÉÊDz¢²»ÊÇËùÓеÄÇéÐζ¼ÊÇÕâÑùµÄ¡£ÒÔÏÂÊÇһЩ¿ÉÄܵ¼ÖÂSessionɥʧµÄÔµ¹ÊÔÓÉ£º
Óû§ä¯ÀÀÆ÷½ûÓÃcookie
ÈôÊÇÓû§ÔÚä¯ÀÀÆ÷ÖнûÓÃÁËcookie£¬ÄÇôsession¾ÍÎÞ·¨Õý³£Ê¹Ó᣽â¾öÒªÁìÊÇÏòÓû§ÏÔʾһ¸ö¹ýʧÐÂÎÅ£¬²¢ÒªÇóËûÃÇÆôÓÃcookie¡£
Àú³ÌÍß½â
ÈôÊÇPHPÀú³ÌÖеÄij¸öÎļþÍß½âÁË£¬sessionÊý¾Ý¿ÉÄÜ»áɥʧ¡£
ЧÀÍÖØÊÓÆô
ÈôÊÇÄúµÄЧÀÍÆ÷ÔÚsessionÊý¾Ý±»´æ´¢Ö®Ç°ÖØÆô£¬sessionÊý¾ÝÒ²»áɥʧ¡£
²¢·¢»á¼û
ÈôÊǶà¸öÓû§Í¬Ê±»á¼ûÄúµÄÍøÕ¾£¬²¢Ê¹ÓÃÏàͬµÄsession ID£¬ÄÇôsessionÊý¾Ý¿ÉÄܻᱻ²î±ðµÄÓû§ÁýÕÖ¡£
Èý¡¢ÔõÑù½â¾öSessionɥʧÎÊÌ⣿
µ±·ºÆðSessionɥʧÎÊÌâʱ£¬ÎÒÃÇ¿ÉÒÔͨ¹ýÒÔÏÂÒªÁì½â¾ö£º
¼ì²éCookieÉèÖÃ
Ê×ÏÈ£¬ÄúÐèҪȷ¶¨ÊÇ·ñ׼ȷÉèÖÃÁËcookie¡£ÔÚconfig/session.phpÎļþÖУ¬Äú¿ÉÒÔÉèÖÃcookieµÄÃû³Æ¡¢ÓòÃû¡¢ÓÐÓÃÆںͷ¾¶¡£
Äú¿ÉÒÔƾ֤ÒÔÏ·½·¨ÉèÖãº
'cookie' => env( 'SESSION_COOKIE_NAME', 'laravel_session' ), 'path' => '/', 'domain' => env('SESSION_DOMAIN', null), 'secure' => env('SESSION_SECURE_COOKIE'), 'http_only' => true,
µÇ¼ºó¸´ÖÆ
¼ì²éSession´æ´¢Çý¶¯
ÈôÊÇÄúʹÓõÄÊÇÎļþ´æ´¢Çý¶¯£¬ÄÇôÔÚЧÀÍÖØÊÓÆôºó£¬sessionÊý¾Ý¾Í»áɥʧ¡£ÈôÊÇÄúÐèÒª¿ç¶à¸öЧÀÍÆ÷¹²ÏísessionÊý¾Ý£¬Äú¿ÉÒÔʹÓÃÊý¾Ý¿â»ò»º´æ´æ´¢Çý¶¯¡£Äú¿ÉÒÔÔÚconfig/session.phpÎļþÖÐÉèÖÃsessionµÄ´æ´¢Çý¶¯¡£
'driver' => env('SESSION_DRIVER', 'file'), 'connection' => env('SESSION_CONNECTION', null), 'table' => 'sessions',
µÇ¼ºó¸´ÖÆ
ÐÞ¸´Session ID³åÍ»
µ±¶à¸öÓû§Ê¹ÓÃÏàͬµÄsession IDʱ£¬ËûÃÇ¿ÉÄÜÁýÕÖÏ໥µÄÊý¾Ý¡£ LaravelÌṩÁËÒ»ÖÖÒªÁìÀ´ÐÞ¸´Session ID³åÍ»¡£ÔÚconfig/session.phpÎļþÖУ¬Äú¿ÉÒÔ½«’encrypt’Ñ¡ÏîÉèÖÃΪtrue£¬ÒÔ¼ÓÃÜSession ID¡£ÕâÑù×ö¿ÉÒÔÈ·±£Ã¿¸öSession ID¶¼ÊÇΨһµÄ¡£
ÖØÐÂÆô¶¯PHPÀú³Ì
ÈôÊÇPHPÀú³ÌÍ߽⣬Äú¿ÉÒÔʵÑéÖØÐÂÆô¶¯Ëü¡£Õâͨ³£¿ÉÒÔÐÞ¸´SessionɥʧÎÊÌâ¡£
ʵÏÖ×Ô¶¯ÉúÑÄSession
ÁíÒ»ÖÖÒªÁìÊÇÔÚÓû§Ã¿´ÎÖ´ÐÐÖ÷Òª²Ù×÷£¨ÀýÈçÌá½»±íµ¥£©Ê±£¬×Ô¶¯ÉúÑÄsession¡£Äú¿ÉÒÔʹÓÃÒÔÏ´úÂëÔÚLaravelÖÐʵÏÖ£º
if (isset($_POST['submit'])) { session_write_close(); }
µÇ¼ºó¸´ÖÆ
ʹÓÃÐÐÁÐ
ÈôÊÇÄúµÄÓ¦ÓóÌÐòÐèÒª²¢·¢´¦Àí¶à¸öÇëÇó£¬Äú¿ÉÒÔʹÓÃÐÐÁÐÀ´´æ´¢sessionÊý¾Ý¡£Õâ¿ÉÒÔÈ·±£Ã¿¸öÇëÇ󶼾ßÓÐ×Ô¼ºµÄ×ÔÁ¦session£¬´Ó¶øïÔÌÁýÕÖÎÊÌâµÄΣº¦¡£
ËÄ¡¢×ܽá
SessionɥʧÊÇÒ»¸ö³£¼ûµÄÎÊÌ⣬¿ÉÊÇÎÒÃÇ¿ÉÒÔͨ¹ý¼ì²écookieÉèÖá¢session´æ´¢Çý¶¯¡¢ÐÞ¸´Session ID³åÍ»¡¢ÖØÐÂÆô¶¯PHPÀú³Ì¡¢ÊµÏÖ×Ô¶¯ÉúÑÄsessionºÍʹÓÃÐÐÁеÈÒªÁìÀ´½â¾ö¡£ÈôÊÇÄúÈÔÈ»Óöµ½ÎÊÌ⣬Äú¿ÉÒÔÉó²éLaravelÎĵµ»ò×ÉѯLaravelÉçÇø¡£ÏàʶÕâЩҪÁìµÄÓŵãºÍÈõµã£¬¿ÉÒÔ×ÊÖúÄú½â¾öLaravel SessionɥʧÎÊÌ⣬²¢È·±£ÄúµÄÓ¦ÓóÌÐòÄܹ»Õý³£ÔËÐС£
ÒÔÉϾÍÊÇlaravel session ɥʧµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡