何时使用URL /会话/ cookie变量? [英] When to use URL/session/cookie variables?

查看:153
本文介绍了何时使用URL /会话/ cookie变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了很多php和javascript,但我认为这是相对语言无关的问题。是否有任何最佳做法,以供何时使用以下各项:




  • 网址变数

  • SESSION变数

  • Cookie



我了解其中的一些内在限制, t ,但似乎他们的使用可能有时重叠,这些实例是我真正要问的。






EDIT
只是为了澄清:我非常熟悉哪个方法的技术性存储在哪里,哪个客户端/服务器可以访问。我正在寻找的是更高级别的东西,例如临时用户设置应该存储在cookie,数据状态信息应该存在于服务器上,等...



谢谢!

解决方案

一般情况下:


  1. 使用URL(GET)参数将简单请求参数发送到服务器,例如。


  2. 使用会话变量(如名称所示)来存储与特定用户会话相关联的临时数据,例如。登录用户的ID或非持久性购物车。


  3. 尽可能避免使用Cookie。请谨慎使用它们来存储与特定计算机/用户配置文件相关联的设置,例如。例如记住此计算机上的用户ID。



I do a lot of php and javascript, but I think this is relatively language-agnostic question. Are there any best-practices for when to use each of:

  • URL variables
  • SESSION variables
  • cookies

I understand the inherent limitations of what some of them can't do, but it seems like their use can overlap sometimes, too, and those instances are what I'm really asking about.


EDIT Just to clarify: I'm pretty familiar with the technicalities of which method is stored where, and which the client/server can access. What I am looking for is something a little higher-level, like "temporary user settings should live in cookies, data state info should live on the server, etc..."

Thanks!

解决方案

In general:

  1. Use URL (GET) parameters for sending simple request parameters to the server, eg. a search query or the page number in a product listing.

  2. Use session variables, as the name indicates, to store temporary data associated with a specific user session, eg. a logged-in user's ID or a non-persistent shopping cart.

  3. Avoid using cookies when possible. Use them sparingly to store settings that are tied to a particular computer / user profile, eg. a setting such as "remember my user ID on this computer".

这篇关于何时使用URL /会话/ cookie变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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