在客户端设置cookie_检测Cookie和JavaScript的客户端浏览器设置

在客户端设置cookie

Introduction and Prerequisites

简介和先决条件

This article describes methods for detecting whether a client browser accepts and returns HTTP cookies and whether the client browser runs JavaScript.  Most client browsers will, by default, be configured to use cookies and JavaScript, but some may not do that, and it may be important to your application design to be aware of these client-side factors as you build your web documents.  For example, most shopping carts rely on cookies to store a pointer to the contents of the cart.  If your client has cookies disabled, the shopping cart would not work.  Rather than simply fail, it would be a better design to be able to tell the client about the dependency.  Or you might have a gallery that used jQuery to provide an attractive client experience.  If you knew that JavaScript was disabled you would be able to adjust the gallery behavior. 

本文介绍了用于检测客户端浏览器是否接受并返回HTTP cookie以及客户端浏览器是否运行JavaScript的方法。 默认情况下,大多数客户端浏览器都将配置为使用Cookie和JavaScript,但有些可能不会这样做,并且在构建Web文档时要意识到这些客户端因素对于您的应用程序设计可能很重要。 例如,大多数购物车都依赖Cookie来存储指向购物车内容的指针。 如果您的客户禁用了Cookie,则购物车将无法使用。 与其说简单地失败,不如说是能够告诉客户有关依赖性的更好的设计。 或者您可能拥有使用jQuery来提供有吸引力的客户体验的画廊。 如果您知道禁用了JavaScript,则可以调整图库的行为。

These concepts seems like common sense in application design, but the client/server relationship has a structure that hinders this common sense approach.  The order of request and response events is an important principle.  All communication is initiated by the client.  The client makes a request, the server-side scripts run, and the server-side scripts are complete before the response is sent to the browser.  As a result, any of the characteristics of the client browser that are not part of the request are invisible to the server-side scripts that create HTML documents.  And the server is a response-only device.  It cannot initiate communication with the client.  How, then, can we "look over the wall" to discern what the client browser will do with the cookies and JavaScript that we might send?

这些概念在应用程序设计中似乎是常识,但是客户/服务器关系的结构阻碍了这种常识方法。 请求和响应事件的顺序是重要的原则。 所有通信均由客户端启动。 客户端发出请求 ,运行服务器端脚本,并且请求的客户端浏览器的任何特征对于创建HTML文档的服务器端脚本都是不可见的。 服务器是仅响应的设备。 它无法启动与客户端的通信。 那么,我们如何才能“窥视墙壁”以辨别客户端浏览器将如何处理我们可能发送的cookie和JavaScript?

In order to understand the logic of these processes, you need to understand the stateless nature of HTTP protocols, and the order of events in a client/server system.  There are two articles here at E-E that can help with the background knowledge you'll need as you read this article.  If you're not familiar with these concepts, please take a moment to read these articles, then come back to this one.

为了了解这些过程的逻辑,您需要了解HTTP协议的无状态性质以及客户端/服务器系统中事件的顺序。 EE上有两篇文章可以帮助您阅读本文时所需要的背景知识。 如果您不熟悉这些概念,请花一点时间阅读这些文章,然后再回到这篇文章。

HTTP Client/Server HTTP客户端/服务器 PHP Sessions PHP会话

Setting Up a Test Bed

设置测试台

Since we will want to be able to test our scripts, we will need a browser that can both accept and refuse cookies, and can enable and disable JavaScript.  We can make these settings in the Firefox browser.  At the time of this writing (November 2014), Firefox is currently at release 33+, and these instructions are applicable to a Windows version of that release.  Mozilla has a way of moving things around from release to release, and you may find in the future that the instructions are no longer directly applicable.  Nevertheless, the concepts will still be workable, and a Google search for these headlines will lead you to an implementation of the concepts.  Similar instructions for Internet Explorer and Google Chrome are included at the end of the article.

由于我们希望能够测试脚本,因此我们需要一个既可以接受也可以拒绝cookie并可以启用和禁用JavaScript的浏览器。 我们可以在Firefox浏览器中进行这些设置。 在撰写本文时(2014年11月),Firefox当前版本为33+,这些说明适用于该版本的Windows版本。 Mozilla提供了一种在各个发行版之间进行迁移的方法,您将来可能会发现这些说明不再直接适用。 尽管如此,这些概念仍然可以使用,并且通过Google搜索这些标题,您可以实现这些概念。 本文末尾包含了针对Internet Explorer和Google Chrome的类似说明。

Enabling and Disabling Cookies in Firefox

在Firefox中启用和禁用Cookies

The path for this process starts with the Firefox menu, hidden behind the three-bar menu button in the upper right of the browser window.  To enable cookies for your test, follow these steps:

此过程的路径从Firefox菜单开始,该菜单隐藏在浏览器窗口右上方的三栏菜单按钮后面。 要为您的测试

1. Click the three-bar menu button to reveal the menu

1.单击三栏菜单按钮以显示菜单

2. Click "Options"

2.点击“选项”

3. Click "Privacy"

3.点击“隐私”

4. Uncheck "Accept cookies from sites"

4.取消选中“接受来自站点的cookie”

5. Click "Exceptions"

5.点击“例外”

6. Type your base URL, for example, Experts-Exchange.com

6.键入您的基本URL,例如

7. Click "Allow for Session"

7.单击“允许会话”

8. Close / OK the menu windows

8.关闭/确定菜单窗口

To disable cookies, follow steps 1-5 above, then:<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值