{"id":18005,"date":"2021-06-24T10:40:07","date_gmt":"2021-06-24T03:40:07","guid":{"rendered":"https:\/\/acaltc.com\/?p=18005"},"modified":"2021-06-24T10:40:07","modified_gmt":"2021-06-24T03:40:07","slug":"session-va-cookie-trong-lap-trinh-web","status":"publish","type":"post","link":"https:\/\/acaltc.com\/en\/session-va-cookie-trong-lap-trinh-web\/","title":{"rendered":"Session v\u00e0 cookie trong l\u1eadp tr\u00ecnh Web"},"content":{"rendered":"

Session, Cookie l\u00e0 2 kh\u00e1i ni\u1ec7m \u0111\u01b0\u1ee3c r\u1ea5t quan tr\u1ecdng \u0111\u1ed1i v\u1edbi c\u00e1c l\u1eadp tr\u00ecnh web. Khi m\u1edbi b\u1eaft \u0111\u1ea7u t\u1eadp l\u00e0m web, nhi\u1ec1u b\u1ea1n ch\u1eafc h\u1eb3n r\u1ea5t hay nh\u1ea7m l\u1eabn gi\u1eefa c\u00e1c kh\u00e1i ni\u1ec7m n\u00e0y. H\u00e3y c\u00f9ng t\u00ecm hi\u1ec3u v\u1ec1 kh\u00e1i ni\u1ec7m c\u00e1ch d\u00f9ng c\u1ee7a Session v\u00e0 Cookie nh\u00e9.<\/strong><\/em><\/p>\n

Session<\/strong><\/h3>\n
Session l\u00e0 g\u00ec?<\/strong><\/h5>\n

\u0110\u00e2y l\u00e0 m\u1ed9t phi\u00ean l\u00e0m vi\u1ec7c \u0111\u01b0\u1ee3c d\u00f9ng trong l\u1eadp tr\u00ecnh web v\u00e0 c\u00f3 th\u1ec3 k\u1ebft n\u1ed1i v\u1edbi database. N\u00f3i m\u1ed9t c\u00e1ch d\u1ec5 hi\u1ec3u, session ch\u00ednh l\u00e0 ch\u01b0\u01a1ng tr\u00ecnh hay c\u00e1ch th\u1ee9c \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng \u0111\u1ec3 l\u01b0u tr\u1eef th\u00f4ng tin c\u1ee7a ng\u01b0\u1eddi d\u00f9ng khi h\u1ecd s\u1eed d\u1ee5ng trang web c\u1ee7a m\u00ecnh.<\/p>\n

Session \u0111\u01b0\u1ee3c l\u01b0u tr\u1eef trong m\u1ed9t t\u1eadp tin b\u1ea5t k\u1ef3 n\u00e0o \u0111\u00f3 c\u1ee7a server. Vi\u1ec7c l\u01b0u tr\u1eef d\u1eef li\u1ec7u trong session kh\u00f4ng ph\u1ee5 thu\u1ed9c v\u00e0o quy\u1ebft \u0111\u1ecbnh c\u1ee7a ng\u01b0\u1eddi d\u00f9ng. Tuy nhi\u00ean, c\u00e1c session th\u00f4ng th\u01b0\u1eddng s\u1ebd ch\u1ec9 l\u01b0u tr\u1eef nh\u1eefng th\u00f4ng tin ng\u1eafn h\u1ea1n m\u00e0 th\u00f4i. V\u00ed d\u1ee5 nh\u01b0 khi b\u1ea1n \u0111\u0103ng nh\u1eadp v\u00e0o m\u1ed9t trang website theo t\u00e0i kho\u1ea3n email v\u00e0 m\u1eadt kh\u1ea9u c\u1ee7a m\u00ecnh \u0111\u01b0\u1ee3c x\u00e1c nh\u1eadn l\u00e0 ch\u00ednh x\u00e1c, khi \u0111\u00f3 m\u1ed9t session s\u1ebd \u0111\u01b0\u1ee3c t\u1ea1o trong m\u00e1y ch\u1ee7 \u0111\u1ec3 l\u01b0u tr\u1eef l\u1ea1i c\u00e1c h\u00e0nh \u0111\u1ed9ng c\u1ee7a b\u1ea1n t\u1edbi khi phi\u00ean \u0111\u01b0\u1ee3c k\u1ebft th\u00fac. \u0110i\u1ec1u n\u00e0y c\u0169ng t\u01b0\u01a1ng t\u1ef1 nh\u01b0 \u0111ang th\u00eam h\u00e0ng h\u00f3a v\u00e0o gi\u1ecf h\u00e0ng nh\u01b0ng ch\u01b0a thanh to\u00e1n.<\/p>\n

T\u1ea1i sao l\u1ea1i c\u1ea7n \u0111\u1ebfn session?<\/strong><\/h5>\n

L\u01b0u tr\u1eef c\u00e1c Session d\u01b0\u1eddng nh\u01b0 r\u1ea5t ph\u1ed5 bi\u1ebfn tr\u00ean c\u00e1c website. Th\u1ef1c ra l\u00fd do cho vi\u1ec7c n\u00e0y c\u0169ng kh\u00e1 d\u1ec5 hi\u1ec3u b\u1edfi c\u00e1c l\u1ee3i \u00edch m\u00e0 n\u00f3 \u0111em l\u1ea1i. Trong c\u00e1c c\u00f4ng vi\u1ec7c giao ti\u1ebfp gi\u1eefa m\u00e1y ch\u1ee7 l\u00e0 website server v\u1edbi tr\u00ecnh duy\u1ec7t th\u00ec s\u1ebd \u0111\u01b0\u1ee3c th\u1ef1c hi\u1ec7n qua h\u00e0ng ho\u1ea1t router tr\u00ean m\u1ea1ng. Nh\u01b0ng v\u1ea5n \u0111\u1ec1 l\u00e0 l\u00e0m sao \u0111\u1ec3 ph\u00e2n bi\u1ec7t \u0111\u01b0\u1ee3c c\u00e1c tr\u00ecnh duy\u1ec7t kh\u00e1c nhau c\u1ee7a ng\u01b0\u1eddi d\u00f9ng?<\/p>\n

V\u00ec v\u1eady khi s\u1eed d\u1ee5ng session s\u1ebd gi\u00fap b\u1ea1n:<\/p>\n