Rails v2.3:会话和cookies之间的区别 [英] Rails v2.3 : Difference between session and cookies

查看:30
本文介绍了Rails v2.3:会话和cookies之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读在线指南(适用于 Rails v2.3)来学习 Rails.该指南很棒,但是,我有一个困惑,那就是:

I am learning Rails by reading the online guide(for Rails v2.3). The guide is great, however, there is a confusion for me, that's:

有一章解释了 Rails 的 Session,另一章解释了 Cookies.分开解释很容易理解,但是当比较两者时,像我这样的读者并没有看到 Session 和 Cookies 之间的显着区别.尤其是什么情况下应该使用session,什么情况下应该使用cookies?

there is a chapter explains the Session of Rails and another chapter explains Cookies of Rails. The explanation is easy to understand separately, but when compare the two, reader like me does not see the significant difference between Session and Cookies . Especially under which situation session should be used and under which situation Cookies should be used ?

另外,在会话章节中,有一个 CookieStore 的概念,那么 CookieStore 和 Cookies 有什么区别?

Besides, in the session chapter, there is a concept of CookieStore , what is the difference between the CookieStore and Cookies then?

有人可以向我解释这些吗?

Could someone explain to me these?

推荐答案

Sessions &Cookie 都能够在两个或多个请求之间存储一些信息(例如:current_user id),否则(在 http 中)是无状态的.

Sessions & Cookies both hold the ability to store some information (e.g : the current_user id) in between two or more requests which (in http) are otherwise stateless.

但 Session 更像是一个抽象概念,与在特定时间内处于某种状态的概念相关:它包含的信息可以存储在数据库中、服务器端文件中、redis 哈希中 <强>或在 cookie 中.

But Session is more of an abstract concept related to the notion of being in a certain state for a specific amount of time : the info it contains can be stored in the database, in a server side file, in a redis hash OR in a cookie.

Cookies 总是小文本文件导航器必须在请求之间存储一些持久性数据......但是在客户端拥有一些数据可能是不安全的,这就是为什么它经常被加密.但这个概念确实可以与会话重叠.

Cookies are always the little text file navigators have to store some persistent data in between requests... But having some data on the client side can be insecure so that's why it is often encrypted. But it's true the notion can overlap with session.

TL;DR : session 持有临时数据的抽象概念.Cookie 是一种(常见的)方法.

TL;DR : session the abstract concept of holding temporary data. Cookies one (common) way of doing it.

这篇关于Rails v2.3:会话和cookies之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆