尊龙凯时人生就是博

ÔõÑùÔÚThinkPHP6ÖÐʹÓÃSession¾ÙÐлỰ²Ù×÷£¿

Ëæ×ÅwebÓ¦ÓóÌÐòµÄÈÕÒæÆÕ¼° £¬»á»°ÖÎÀí±äµÃÔ½À´Ô½Ö÷Òª¡£ÔÚwebÓ¦ÓóÌÐòÖÐ £¬»á»°¾­³£ÓÃÓÚ¸ú×ÙÓû§Ô˶¯ £¬´æ´¢Óû§Êý¾ÝÒÔ¼°Î¬»¤Óû§×´Ì¬¡£ÔÚphpÖÐ £¬»á»°ÖÎÀíͨ³£Ê¹ÓÃsessionÀ´ÊµÏÖ¡£thinkphp6ÌṩÁËÖÜÈ«µÄ»á»°Ö§³Ö £¬¿ÉÒÔÇáËɵØÓësession½»»¥¡£±¾ÎĽ«ÏÈÈÝÔõÑùÔÚthinkphp6ÖÐʹÓÃsession¾ÙÐлỰ²Ù×÷¡£

¿ªÆôSessionÖ§³Ö

ÔÚThinkPHP6ÖÐ £¬¿ÉÒÔͨ¹ýÉèÖÃÎļþÀ´¿ªÆôSessionÖ§³Ö¡£ÔÚconfigĿ¼ÏµÄapp.phpÎļþÖÐ £¬¿ÉÒÔÕÒµ½ÒÔÏÂÉèÖÃÏ

// sessionÉèÖÃ
'session'                 => [
    'prefix'         => 'think',
    'type'           => '',
    'auto_start'     => true,
    'httponly'       => true,
    'secure'         => false,
    'expire'         => 1440,
    'use_trans_sid'  => true,
    'cookie_domain'  => '',
    'cookie_path'    => '/',
    'cookie_lifetime' => 0,
    'cookie'         => null,
],

µÇ¼ºó¸´ÖÆ

ͨ¹ýÐ޸ĸÃÉèÖÃÏî £¬¿ÉÒÔÇáËɵؿªÆôSessionÖ§³Ö¡£ÆäÖÐ £¬prefixÊÇSession±äÁ¿Ç°×º £¬typeÊÇSession´æ´¢ÀàÐÍ£¨¿ÉÒÔÊÇfile¡¢redis¡¢memcachedµÈ£© £¬auto_startÊÇÊÇ·ñ×Ô¶¯¿ªÆôSession £¬httponlyÊÇÊÇ·ñÖ»ÄÜͨ¹ýHTTPЭÒé»á¼ûCookie £¬secureÊÇÊÇ·ñʹÓÃÇå¾²HTTPЭÒé £¬expireÊÇSessionÓâÆÚʱ¼ä£¨µ¥Î»ÎªÃ룩 £¬use_trans_sidÊÇÊÇ·ñÆôÓÃ͸Ã÷SessionID £¬cookie_domainÊÇSessionµÄCookieÓòÃû £¬cookie_pathÊÇSessionµÄCookie·¾¶ £¬cookie_lifetimeÊÇSessionµÄCookieÓâÆÚʱ¼ä£¨µ¥Î»ÎªÃ룩 £¬cookieÊÇÊÖ¶¯ÉèÖÃSessionµÄCookieÑ¡Ïî¡£

×îÏȻỰ

ÔÚ¿ªÆôSessionÖ§³ÖÖ®ºó £¬¿ÉÒÔʹÓÃSessionÀàÀ´×îÏȻỰ¡£ÔÚ¿ØÖÆÆ÷»òÄ£×ÓÖÐ £¬Í¨¹ýŲÓÃSessionÀàµÄstartÒªÁìÀ´×îÏȻỰ £¬ÈçÏÂËùʾ£º

use thinkacadeSession;

...

// ×îÏȻỰ
Session::start();

µÇ¼ºó¸´ÖÆ

ÉèÖÃSession±äÁ¿

ÔڻỰʱ´ú £¬¿ÉÒÔͨ¹ýSessionÀàµÄsetÒªÁìÀ´ÉèÖÃSession±äÁ¿¡£ÕâЩ±äÁ¿½«»áÔÚÕû¸ö»á»°Ê±´ú¼á³ÖÎÈ¹Ì £¬Ö±µ½»á»°¿¢Ê»òÕß±»ÊÖ¶¯É¾³ý¡£Ê¹ÓÃÒªÁìÈçÏ£º

use thinkacadeSession;

...

// ÉèÖÃSession±äÁ¿
Session::set('key', 'value');

µÇ¼ºó¸´ÖÆ

¿ÉÒÔʹÓÃSessionÀàµÄgetÒªÁìÀ´»ñÈ¡Session±äÁ¿µÄÖµ £¬ÈçÏÂËùʾ£º

use thinkacadeSession;

...

// »ñÈ¡Session±äÁ¿
$value = Session::get('key');

µÇ¼ºó¸´ÖÆ

ɾ³ýSession±äÁ¿

ͨ¹ýŲÓÃSessionÀàµÄdeleteÒªÁì £¬¿ÉÒÔɾ³ýSession±äÁ¿¡£Ê¹ÓÃÒªÁìÈçÏ£º

use thinkacadeSession;

...

// ɾ³ýSession±äÁ¿
Session::delete('key');

µÇ¼ºó¸´ÖÆ

Çå¿ÕSession

ÈôÊÇÐèÒªÔڻỰʱ´úɨ³ýËùÓÐSession±äÁ¿ £¬¿ÉÒÔʹÓÃSessionÀàµÄclearÒªÁì¡£ÈçÏÂËùʾ£º

use thinkacadeSession;

...

// Çå¿ÕSession
Session::clear();

µÇ¼ºó¸´ÖÆ

ÑéÖ¤Session

ÔڻỰʱ´ú £¬¿ÉÒÔʹÓÃSessionÀàµÄhasÒªÁìÀ´ÑéÖ¤Session±äÁ¿ÊÇ·ñ±£´æ¡£ÈçÏÂËùʾ£º

use thinkacadeSession;

...

// ÑéÖ¤Session±äÁ¿ÊÇ·ñ±£´æ
if (Session::has('key')) {
    // ±£´æ
} else {
    // ²»±£´æ
}

µÇ¼ºó¸´ÖÆ

ÉÁ´æÊý¾Ý

ÉÁ´æÊý¾ÝÊÇÖ¸Ö»ÄÜÔÚÏÂÒ»´Î»á»°Ê±´úʹÓõÄÑÓ³ÙÉèÖÃSession±äÁ¿¡£¿ÉÒÔͨ¹ýSessionÀàµÄflashÒªÁìÀ´ÉèÖÃÉÁ´æÊý¾Ý¡£Ê¹ÓÃÒªÁìÈçÏ£º

use thinkacadeSession;

...

// ÉèÖÃÉÁ´æÊý¾Ý
Session::flash('key', 'value');

µÇ¼ºó¸´ÖÆ

ÔÚÏÂÒ»´ÎÇëÇóʱ £¬¿ÉÒÔʹÓÃSessionÀàµÄgetÒªÁìÀ´»ñÈ¡ÉÁ´æÊý¾Ý¡£ÈçÏÂËùʾ£º

use thinkacadeSession;

...

// »ñÈ¡ÉÁ´æÊý¾Ý
$value = Session::get('key');

µÇ¼ºó¸´ÖÆ

¿¢Ê»Ự

ÔڻỰ¿¢ÊÂʱ £¬¿ÉÒÔͨ¹ýŲÓÃSessionÀàµÄdestroyÒªÁìÀ´É¨³ýËùÓлỰÊý¾Ý £¬²¢ÊÍ·ÅËùÓлỰ×ÊÔ´¡£Ê¹ÓÃÒªÁìÈçÏ£º

use thinkacadeSession;

...

// ¿¢Ê»Ự
Session::destroy();

µÇ¼ºó¸´ÖÆ

±¾ÎÄÏÈÈÝÁËÔõÑùÔÚThinkPHP6ÖÐʹÓÃSession¾ÙÐлỰ²Ù×÷¡£ÕâÈÝÒ×Ã÷È·²¢ÇÒÒ×ÓÚʹÓà £¬¿ÉÓÃÓÚ¸ú×ÙÓû§Ô˶¯ £¬´æ´¢Óû§Êý¾ÝÒÔ¼°Î¬»¤Óû§×´Ì¬¡£ÈôÊÇÄúÔÚʹÓÃÖÐÓöµ½ÎÊÌâ»òÕßÓÐÆäËûÒÉÎÊ £¬¿ÉÒԲο¼¹Ù·½Îĵµ»òÕßÔÚÉçÇøÖоÙÐÐÌáÎÊ £¬ÒÔ±ã»ñµÃ¸üºÃµÄ×ÊÖú¡£

Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»

ÒÔÉϾÍÊÇÔõÑùÔÚThinkPHP6ÖÐʹÓÃSession¾ÙÐлỰ²Ù×÷£¿µÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

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

18523999891

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

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

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