×ðÁú¿­Ê±¹ÙÍøµÇ¼

laravel 5.7»á¼û²»ÁË·ÓÉ

Ëæ×Å laravel 5.7 µÄÍƳö £¬ÓÐÐí¶àÓû§·´Ó¦»á¼û·ÓÉ·ºÆðÁËÎÊÌâ¡£Õâ¸öÎÊÌâµÄ·ºÆð¿ÉÄÜ»áÈÃÄãÔÚ¿ª·¢Àú³ÌÖÐÆÌÕÅ´ó×ÚµÄʱ¼äÀ´´¦Àí¡£ÎªÁË×ÊÖú¸÷È˽â¾öÕâ¸öÎÊÌâ £¬±¾ÎĽ«ÏêϸÏÈÈÝ laravel 5.7 »á¼û²»ÁË·ÓɵĽâ¾ö¼Æ»®¡£

Ê×ÏÈÎÒÃÇÐèÒªÏàʶ Laravel 5.7 µÄһЩÐÂת±ä £¬ÕâЩת±ä¿ÉÄܻᵼÖÂ֮ǰµÄ´úÂëÎÞ·¨Õý³£ÔËÐС£ÆäÖÐ×îÖ÷ÒªµÄÒ»¸öת±äÊÇĬÈÏÌí¼ÓÁË CSRF ± £»¤ÖÐÑë¼þ¡£ÕâÆäÖÐÑë¼þ¿ÉÒÔÈ·±£Óû§Ìá½»µÄ±íµ¥Êý¾ÝÊÇ·ñÀ´×ÔÓÚÄãµÄÓ¦ÓóÌÐò £¬±ÜÃâÓ¦ÓóÌÐòÔâÊÜ CSRF ¹¥»÷¡£

CSRF ± £»¤ÖÐÑë¼þÔÚ Laravel 5.6 ÖÐÒѾ­±£´æ £¬µ«Ä¬Èϲ¢Ã»ÓÐÆôÓᣵ«ÔÚ Laravel 5.7 ÖÐ £¬Laravel ÍŶÓĬÈÏÆôÓÃÁËÕâÆäÖÐÑë¼þ¡£Òò´Ë £¬ÔÚ Laravel 5.7 ÖÐ £¬Ê¹ÓÃ±íµ¥Ìá½»Êý¾ÝʱÐèÒªÌí¼Ó CSRF ÁîÅÆ¡£

½â¾öÒªÁ죺

ÓÐÁ½ÖÖÒªÁì¿ÉÒÔ½â¾ö Laravel 5.7 »á¼û²»ÁË·ÓɵÄÎÊÌâ¡£µÚÒ»ÖÖÒªÁìÊÇÔÚ web.php ÎļþÖÐÌí¼Ó CSRF ÁîÅÆ¡£µÚ¶þÖÖÒªÁìÊǽûÓà CSRF ± £»¤ÖÐÑë¼þ¡£

ÒªÁìÒ»£ºÔÚ web.php ÎļþÖÐÌí¼Ó CSRF ÁîÅÆ

Laravel 5.7 ´úÂëµÄ RouteServiceProvider.php ÖÐĬÈÏʹÓÃÁË web ÖÐÑë¼þ×é £¬Òò´Ë £¬ÔÚ web.php ÎļþÖÐÌí¼Ó CSRF ÁîÅÆ×î¼òÆÓµÄÒªÁì¾ÍÊÇʹÓà {{ csrf_field() }} ÒªÁì¡£

ÀýÈç £¬ÈôÊÇÄãÓÐÒ»¸ö´¦Àí POST ÇëÇóµÄ·ÓÉ£º

Route::post(‘/foo’, function () {

return 'Hello World';

µÇ¼ºó¸´ÖÆ

});

ÄãÐèÒªÔÚ±íµ¥ÖÐÌí¼Ó {{ csrf_field() }} ÒªÁìÀ´ÌìÉú CSRF ÁîÅÆ£º

{{ csrf_field() }}
<!-- ... -->

µÇ¼ºó¸´ÖÆ

Õâ¸öÒªÁì¿ÉÒÔÈ·±£ÄãµÄ Laravel 5.7 Ó¦ÓóÌÐò¿ÉÒÔÕý³£´¦Àí POST ÇëÇó¡£

ÒªÁì¶þ£º½ûÓà CSRF ± £»¤ÖÐÑë¼þ

½ûÓà CSRF ± £»¤ÖÐÑë¼þÊÇÁíÒ»¸ö½â¾ö Laravel 5.7 »á¼û²»ÁË·ÓɵÄÒªÁì¡£ËäÈ»ÕâÖÖÒªÁì¿ÉÄÜ»áÉÔ΢½µµÍÄãµÄ Laravel Ó¦ÓóÌÐòµÄÇå¾²ÐÔ £¬µ«ÈôÊÇÄãµÄÓ¦ÓóÌÐò²»»áÊܵ½ CSRF ¹¥»÷µÄÍþв £¬ÄÇôÕâÖÖÒªÁìÊÇ¿ÉÐеÄ¡£

Òª½ûÓà CSRF ± £»¤ÖÐÑë¼þ £¬ÄãÐèÒªÔÚ VerifyCsrfToken ÀàµÄ $except ÊôÐÔÖÐÌí¼ÓÒªºöÂ﵀ URI¡£

·­¿ª app/Http/Middleware/VerifyCsrfToken.php Îļþ £¬È»ºóÔÚ $except ÊôÐÔÖÐÌí¼ÓÒªºöÂԵķÓÉ£º

protected $except = [

'your-route-to-ignore'

µÇ¼ºó¸´ÖÆ

];

ÀýÈç £¬¼ÙÉèÄãÏëºöÂÔ¡°register¡±Â·ÓÉ£º

protected $except = [

'register'

µÇ¼ºó¸´ÖÆ

];

Õâ¸öÒªÁì¿ÉÒÔÈ·±£ÄãµÄ Laravel 5.7 Ó¦ÓóÌÐò¿ÉÒÔÕý³£´¦ÀíËùÓÐÇëÇó¡£

½áÂÛ£º

×ܵÄÀ´Ëµ £¬ÔÚ Laravel 5.7 Öлá¼û²»ÁË·ÓɵÄÎÊÌâÖ÷ÒªÊÇÓÉÓÚĬÈÏÆôÓÃÁË CSRF ± £»¤ÖÐÑë¼þËùµ¼ÖµÄ¡£Òò´Ë £¬ÈôÊÇÄãÔÚ¿ª·¢µÄÀú³ÌÖÐÓöµ½ÁËÕâ¸öÎÊÌâ £¬¿ÉÒÔʵÑéʹÓÃÕâÁ½ÖÖÒªÁìÀ´½â¾ö¡£ÈôÊÇÄãÒª½ûÓà CSRF ± £»¤ÖÐÑë¼þ £¬Ó¦¸Ã½ö¶ÔÄÇЩ²»Éæ¼°Ãô¸Ð»òÖ÷ÒªÊý¾ÝµÄ·ÓÉʹÓá£Õâ¸öÒªÁì¿ÉÄÜ»áÂÔ΢½µµÍÄãµÄ Laravel Ó¦ÓóÌÐòµÄÇå¾²ÐÔ £¬Òò´Ë½¨ÒéʹÓÃÒªÁìÒ»À´È·±£ÄãµÄÓ¦ÓóÌÐòµÄÇå¾²ÐÔ¡£

ÒÔÉϾÍÊÇlaravel 5.7»á¼û²»ÁË·ÓɵÄÏêϸÄÚÈÝ £¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

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

Ïà¹ØÐÂÎÅ

ÁªÏµ×ðÁú¿­Ê±¹ÙÍøµÇ¼

18523999891

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

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

QR code
ÍøÕ¾µØͼ