尊龙凯时人生就是博

Laravel¿ª·¢£ºÔõÑùʹÓÃLaravel SessionÖÎÆÊÎö»°£¿

laravel¿ª·¢£ºÔõÑùʹÓÃlaravel sessionÖÎÆÊÎö»°£¿

ÔÚLaravelÓ¦ÓóÌÐòÖÐ £¬»á»°ÖÎÀíÊǺÜÊÇÖ÷ÒªµÄÒ»²¿·Ö¡£»á»°ÊÇÒ»ÖÖ´æ´¢ÔÚЧÀÍÆ÷¶ËµÄÊý¾Ý½á¹¹ £¬ÓÃÓÚ´æ´¢Ó¦ÓóÌÐòÖеÄÓû§Ìض¨Ãü¾Ý¡£ÕâЩÊý¾Ý¿ÉÒÔͨ¹ýÈκÎÒ³Ãæ»òÇëÇó»á¼û £¬²¢ÇÒ¿ÉÒÔÔÚÓû§»á»°Ê±´ú¼á³ÖÎȹÌ¡£Laravel¿ò¼ÜÌṩÁËSessionÀà £¬ÓÃÓÚ´¦ÀíÓ¦ÓóÌÐòÖеÄÓû§»á»°¡£

±¾ÎĽ«ÏÈÈÝÔõÑùʹÓÃLaravel SessionÀ´ÖÎÆÊÎö»°¡£

Ò»¡¢Ê²Ã´ÊǻỰ

»á»°ÊÇÒ»ÖÖ´æ´¢ÔÚЧÀÍÆ÷¶ËµÄÊý¾Ý½á¹¹ £¬ÓÃÓÚ´æ´¢Ó¦ÓóÌÐòÖеÄÓû§Ìض¨Ãü¾Ý¡£ÓëCookie²î±ð £¬»á»°Êý¾Ý´æ´¢ÔÚЧÀÍÆ÷¶Ë £¬Òò´ËÓû§ÎÞ·¨Éó²é»òÐ޸ĸÃÊý¾Ý¡£

ÔÚLaravelÖÐ £¬»á»°Êý¾Ý´æ´¢ÔÚЧÀÍÆ÷¶ËµÄÎļþ»òÊý¾Ý¿âÖÐ £¬¶ø²»ÊÇCookieÖС£µ±Óû§»á¼ûÓ¦ÓóÌÐòʱ £¬Laravel»áÌìÉúΨһµÄ»á»°ID £¬½«Æä´æ´¢ÔÚCookieÖÐ £¬²¢½«Ïà¹ØÊý¾Ý´æ´¢ÔÚЧÀÍÆ÷¶ËµÄÎļþ»òÊý¾Ý¿âÖС£Ã¿´ÎÓû§»á¼ûÓ¦ÓóÌÐòʱ £¬Laravel»áƾ֤»á»°ID´ÓЧÀÍÆ÷¼ìË÷Ïà¹ØÊý¾Ý £¬ÕâÑùÎÒÃǾͿÉÒÔʵÏÖ¿çÒ³Ãæ»ò¿çÇëÇó´æ´¢ºÍ»á¼ûÊý¾Ý¡£

¶þ¡¢ÆôÓúÍÉèÖÃSession

ÔÚLaravelÓ¦ÓóÌÐòÖÐ £¬SessionЧÀÍĬÈÏÆôÓà £¬²¢Ê¹ÓÃcookie´æ´¢»á»°ID¡£ÎÒÃÇ¿ÉÒÔÔÚconfig/session.phpÎļþÖÐÕÒµ½ÓйػỰµÄÉèÖá£ÒÔÏÂÊÇһЩ³£ÓõÄÉèÖÃÑ¡Ï

1.¡®driver¡¯Ñ¡ÏîÖ¸¶¨»á»°Êý¾ÝµÄ´æ´¢·½·¨¡£LaravelÌṩÁ˶àÖÖÑ¡Ïî £¬°üÀ¨file(ĬÈÏÑ¡Ïî £¬½«Êý¾Ý´æ´¢ÔÚЧÀÍÆ÷¶ËµÄÎļþÖÐ)¡¢cookie(½«Êý¾Ý´æ´¢ÔÚcookieÖÐ)¡¢database(½«Êý¾Ý´æ´¢ÔÚÊý¾Ý¿âÖÐ)ºÍredis(½«Êý¾Ý´æ´¢ÔÚredisÖÐ)¡£

2.¡®lifetime¡¯Ñ¡ÏîÖ¸¶¨»á»°Êý¾ÝµÄÉúÃüÖÜÆÚ £¬ÒÔÃëΪµ¥Î»¡£

3.¡®encrypt¡¯Ñ¡ÏîÖ¸¶¨ÊÇ·ñÓ¦¼ÓÃܻỰÊý¾Ý¡£

4.¡®domain¡¯Ñ¡ÏîÖ¸¶¨cookieµÄÓò¡£

5.¡®path¡¯Ñ¡ÏîÖ¸¶¨cookieµÄ·¾¶¡£

ÔÚconfig/session.phpÎļþÖÐÐÞ¸ÄÕâЩÉèÖÃÑ¡Ïî¼´¿É¡£

Èý¡¢ÔÚLaravelÖÐʹÓÃSession

1.ÆôÓÃSessionЧÀÍ

ÔÚʹÓÃLaravel SessionЧÀÍ֮ǰ £¬ÎÒÃDZØÐèÆôÓÃËü¡£SessionЧÀÍÒÑÔÚLaravelÖÐ×¢²á £¬Òò´ËÎÒÃÇÎÞÐèÊÖ¶¯ÆôÓÃËü¡£ÎÒÃÇ¿ÉÒÔʹÓÃLaravelÄÚÖõÄfacadeÀàSessionÀ´»á¼ûSessionЧÀÍ¡£¸ÃÀàÌṩÁËÐí¶àÓÐÓõÄÒªÁì £¬ÀýÈçget()¡¢put()ºÍpull()¡£

ÒªÊìϤSessionЧÀ͵Ĺ¦Ð§ £¬ÇëÉó²éʾÀý£º

namespace AppHttpControllers;
use IlluminateHttpRequest;
use IlluminateSupportFacadesSession;
class UserController extends Controller
{
    public function index(Request $request)
    {
        // ´æ´¢Ò»¸ö Session Öµ...
        Session::put('key', 'value');
        // »ñÈ¡Ò»¸ö Session Öµ...
        $value = Session::get('key');
        // ɾ³ýÒ»¸ö Session Öµ...
        Session::forget('key');
        // ÓÀÊÀµÄɾ³ýÒ»¸ö Session Öµ...
        Session::flush();
        // ÖØÐÂÌìÉú Session ID...
        Session::regenerate();
    }
}

µÇ¼ºó¸´ÖÆ

2.½«Êý¾Ý´æ´¢ÔÚSessionÖÐ

ÎÒÃÇ¿ÉÒÔʹÓÃSession::put()ÒªÁ콫Êý¾Ý´æ´¢ÔÚSessionÖÐ £¬ÈçÏÂËùʾ£º

$val = 'Hello World';
Session::put('key', $val);

µÇ¼ºó¸´ÖÆ

3.´ÓSessionÖмìË÷Êý¾Ý

ÎÒÃÇ¿ÉÒÔʹÓÃSession::get()ÒªÁì´ÓSessionÖмìË÷Êý¾Ý £¬ÈçÏÂËùʾ£º

$val = Session::get('key');

µÇ¼ºó¸´ÖÆ

4.´ÓSessionÖÐɾ³ýÊý¾Ý

ÎÒÃÇ¿ÉÒÔʹÓÃSession::forget()ÒªÁì´ÓSessionÖÐɾ³ýÊý¾Ý £¬ÈçÏÂËùʾ£º

Session::forget('key');

µÇ¼ºó¸´ÖÆ

5.Çå¿ÕSession

ÎÒÃÇ¿ÉÒÔʹÓÃSession::flush()ÒªÁìÇå¿ÕSessionÖеÄËùÓÐÊý¾Ý £¬ÈçÏÂËùʾ£º

Session::flush();

µÇ¼ºó¸´ÖÆ

6.ÖØÐÂÌìÉúSession ID

ÎÒÃÇ¿ÉÒÔʹÓÃSession::regenerate()ÒªÁìÖØÐÂÌìÉúSession ID £¬ÈçÏÂËùʾ£º

Session::regenerate();

µÇ¼ºó¸´ÖÆ

ËÄ¡¢×ܽá

LaravelÌṩÁËÒ×ÓÚʹÓõÄSessionЧÀÍ £¬ÓÃÓÚÔÚÓ¦ÓóÌÐòÖÐÖÎÀíÓû§»á»°¡£ÎÒÃÇ¿ÉÒÔʹÓÃSessionÀàÌṩµÄÒªÁìÀ´´æ´¢¡¢¼ìË÷ºÍɾ³ýí§ÒâÊý¾Ý¡£ÔÚLaravelÓ¦ÓóÌÐòÖÐÖÎÀíÓû§Ìض¨Ãü¾Ýʱ £¬SessionЧÀÍÊÇÒ»¸öºÜÊÇÖ÷ÒªºÍÓÐÓõŤ¾ß¡£

ÒÔÉϾÍÊÇLaravel¿ª·¢£ºÔõÑùʹÓÃLaravel SessionÖÎÆÊÎö»°£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí £¬°æȨÕùÒéÓë±¾Õ¾ÎÞ¹Ø £¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È £¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ £¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢ £¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢ £¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

18523999891

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎå £¬9:30-18:30 £¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ