Cookie 和 Session 的区别

首先 Cookie 和 Session 的最大区别是,Cookie 是保存在客户端,与域名相绑定,比如与 www.tonywang.io 绑定的 Cookie 不能被 api.tonywang.io 访问,反之亦然。

而 Session 则是保存在服务器端,每个 session 代表一个用户访问,从用户打开浏览器访问页面开始到用户关闭当前页面结束。

相较于保存在客户端的 cookie,Session 保存在服务器端,安全性更高。

两者主要区别是:

  1. Cookie 包含用户信息,保存在客户端,Session 保存在服务器端。
  2. Cookie 不依赖于 Session,而 Session 依赖于 Cookie。
  3. Cookie 的过期时间根据设置而定,Session 在用户关闭浏览器时失效。
  4. Cookie 最大为 4KB,而 Session 则无限制
  5. Cookie 没有一个类似 unsetcookie() 的函数摧毁掉相关信息,而 Session 则有 Session_destroy().

更多:https://www.guru99.com/difference-between-cookie-session.html

comments powered by Disqus

Tags

abcs accept acid activemq affinity algorithm allocation android array async aws b+tree b-tree backoff benchmark best-practices bfs big-o bigquery bind bitcount blog break broker bubble buffer cache cap cert cgroups channel citus class classmethod closure closures cluster concurrency config consistency consumer container context cookie cors crawler cronjob csrf ctr data-science data-structure database datadog dataflow datascience decorator deepcopy defer dfs distributed django dns docker double-shipping drf ecosia elastic-search enumerate epoll equal errgroup escaping event extra fabric2 facebook-pixel financial-report flask flutter forward-proxy freelance frontend frp garbage-collector gc gcp generator gesture get gil git golang goroutine graphql ha handbook haproxy hash hash-slot hashring hashtable hpa http http-auth http-proxy http_proxy https index init innodb instagram intention-lock intergration interview ios is javascript jinja2 jobboard json jwt k8s kafka kibana kqueue label lambda layer4 layer7 lean levels.io linked-list linux list listen loadbalancer lock logs long-tail lru marketing master matplotlib memory merge metaclass metaprogramming metrics metrics-server microservices mitm mobile model mongo mongoose mq myisam mysql namespace nat netflix network network-extension nginx nodejs nomad nosql notification npm oodesign openssl optimization orm osi pandas parallelism paramiko parkinglot patroni permission pg pipeline pixelme post postgresql postresql prefetch_related prerender private-key process proxy proxycommand put pvm python queue rabbitmq rbac react-native reactive reactjs rebase redis redis-cluster replication resource rest restfulapi retargeting retry revenue reverse-proxy rocketmq rsa rxswift saas scaffold scaleable search-engine security select seo serverless service session set shadosocks shadowsocks shard sharding shell shopify sigint signal sigterm singleton slack slave slow-query sniper sns socket socks5 source-code spa sql sqlalchemy sqs ssh ssl ssl-pinning stack startup state stateful stateless staticmethod string struct swift swiftui switch syscall system-design systemctl tcp tcp-proxy thread tmpreaper token traefik trustkit tunning type typeform udp userdefaults variable vc voidcallback vpn vuejs weak web web-development where widget with yarn zset 削峰 单例模式 宽索引 异步 看源码学-golang 窄索引 解耦 跨域 跳板机



Archives

2020 (6)
2019 (157)
0001 (5)