cookie

cookie封装函数

狂风中的少年 提交于 2019-12-03 04:41:06
cookie 写入的封装,读取的封装,删除某个属性的封装 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> </head> <body> <button class="btn">按钮</button> <script> function setCookie(attr,value,expires){ var date=new Date(); var time =date.getTime()+expires*24*3600*1000; date.setTime(time); document.cookie=attr+"="+value+";expires="+date.toUTCString() } setCookie("dfc",11,1); setCookie("lx",222,1); setCookie("hh",33,1); function getCookie(attr) { var cookie

nodeJs学习-08 cookie、session

依然范特西╮ 提交于 2019-12-03 04:39:58
http-无状态的:两次访问之间,无区别,cookie可解决 cookie:在浏览器保存一些数据,每次请求都会带过来;   弊端:可以查看修改,并不安全、大小有限(4K)   读取--cookie-parser   发送--    session:保存数据,保存在服务端,更加安全,大小无限   基于cookie实现,通过cookie读取session值;cookie中会有一个session的ID,服务器利用session_id找到session文件、读取、写入   隐患:session劫持--cookie加密、定期更换等   cookie-session 1、发送cookie   res.secret(签名);   res.cookie(名字,值,{path:'/',maxAge:毫秒单位的有效期,signed:true} 2、读取cookie   依赖cookie-parser 中间件 签名     cookie-encrypter 中间件 加密   server.use(cookieParser('asgewrwrfsf')); //签名秘钥 必须和req.secret的一致     console.log('未签名的cookie:',req.cookies);   console.log('签名的cookie',req.signedCookies); 3、删除cookie  

Cookie防篡改机制

我与影子孤独终老i 提交于 2019-12-03 04:30:12
本文转载于: 猿2048 网站➭ https://www.mk2048.com/blog/blog.php?id=hb1kac2iab 一、为什么Cookie需要防篡改 为什么要做Cookie防篡改,一个重要原因是 Cookie中存储有判断当前登陆用户会话信息(Session)的会话票据-SessionID和一些用户信息 。 当发起一个HTTP请求,HTTP请求头会带上Cookie,Cookie里面就包含有SessionID。 后端服务根据SessionID,去获取当前的会话信息。如果会话信息存在,则代表该请求的用户已经登陆。 服务器根据登陆用户的权限,返回请求的数据到浏览器端。 因为Cookie是存储在客户端,用户可以随意修改。所以,存在一定的安全隐患。 二、例子 username 是为了通俗易懂地解释这个概念,实际项目都不会这么做的,周知。 用户 wall 在浏览器端输入用户名密码,发起POST请求到后端服务器。后端服务器验证合法,返回Response,并 Set-Cookie 为 sessionid=***;username=wall; 。 浏览器端在接收到HTTP响应后,发现 Set-Cookie ,将其存入本地内存或硬盘中。 浏览器端再次发起请求,带上Cookie信息 sessionid=***;username=wall; ,请求修改自己的头像信息。 服务器根据

flutter webview_flutter 设置cookies

孤街浪徒 提交于 2019-12-03 04:15:31
WebViewController _controller; onWebViewCreated: (WebViewController wvc) { _controller = wvc; } onPageFinished: (String value) { _controller.evaluateJavascript( 'document.cookie = "SESSIONID=612bc4822b6996d6f335a963c20eb541fba72985; path=/"') } 设置cookies需要注意时机,这里是在页面加载完成后才设置cookie 来源: https://www.cnblogs.com/qqcc1388/p/11776527.html

协议--Http

我是研究僧i 提交于 2019-12-03 03:39:35
转:https://www.cnblogs.com/niumoo/p/11763249.html 互联网基础协议 - HTTP HTTP的简介 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议。所有的WWW文件都必须遵守这个标准。 HTTP是一个基于TCP/IP通信协议来传递数据(HTML 文件, 图片文件, 查询结果等)。 HTTP是一个属于应用层的面向对象的协议,由于其简捷、快速的方式,适用于分布式超媒体信息系统。它于1990年提出,经过几年的使用与发展,得到不断地完善和扩展。目前在WWW中使用的是HTTP/1.0的第六版,HTTP/1.1的规范化工作正在进行之中,而且HTTP-NG(Next Generation of HTTP)的建议已经提出。 HTTP协议工作于客户端-服务端架构为上。浏览器作为HTTP客户端通过URL向HTTP服务端即WEB服务器发送所有请求。Web服务器根据接收到的请求后,向客户端发送响应信息。 HTTP的特点 支持客户/服务器模式。 简单快速:客户向服务器请求服务时,只需传送请求方法和路径。请求方法常用的有GET、HEAD、POST。每种方法规定了客户与服务器联系的类型不同。 由于HTTP协议简单,使得HTTP服务器的程序规模小,因而通信速度很快。 灵活

【1101 | Day58】一篇文章彻底理解cookie,session,token

痴心易碎 提交于 2019-12-03 03:37:46
目录 彻底理解cookie,session,token 发展史 Cookie Session Token 彻底理解cookie,session,token 发展史 1、很久很久以前,Web 基本上就是文档的浏览而已, 既然是浏览,作为服务器, 不需要记录谁在某一段时间里都浏览了什么文档,每次请求都是一个新的HTTP协议, 就是请求加响应, 尤其是我不用记住是谁刚刚发了HTTP请求, 每个请求对我来说都是全新的。这段时间很嗨皮 2、但是随着交互式Web应用的兴起,像在线购物网站,需要登录的网站等等, 马上就面临一个问题,那就是要管理会话,必须记住哪些人登录系统, 哪些人往自己的购物车中放商品, 也就是说我必须把每个人区分开,这就是一个不小的挑战,因为HTTP请求是无状态的 ,所以想出的办法就是给大家发一个会话标识(session id), 说白了就是一个随机的字串,每个人收到的都不一样, 每次大家向我发起HTTP请求的时候,把这个字符串给一并捎过来, 这样我就能区分开谁是谁了 3、这样大家很嗨皮了,可是服务器就不嗨皮了,每个人只需要保存自己的session id,而服务器要保存所有人的session id ! 如果访问服务器多了, 就得由成千上万,甚至几十万个。 这对服务器说是一个巨大的开销 , 严重的限制了服务器扩展能力, 比如说我用两个机器组成了一个集群,

Using IIS Rewrite to add HttpOnly Flag To Cookies Not Working

匿名 (未验证) 提交于 2019-12-03 03:12:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I found numerous examples of adding the HttpOnly to my cookies but it does not work for me and I am not sure why. All the examples I found were the same and I copied this one from one of the posts that I had found. I am using .NET 3.5 under IIS 7.0. Hopefully someone can tell me what I am doing wrong? Thanks <rewrite> <outboundRules> <rule name="Add HttpOnly" preCondition="No HttpOnly"> <match serverVariable="RESPONSE_Set_Cookie" pattern=".*" negate="false" /> <action type="Rewrite" value="{R:0}; HttpOnly" /> <conditions> </conditions> <

Why do I get undefined index while using cookie in PHP?

匿名 (未验证) 提交于 2019-12-03 03:10:03
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: If I use the following basic code if (! defined ( 'NAME_COOKIE' ) ) define ( 'NAME_COOKIE' , "storedusername" ); $cookie_domain = "." . $_SERVER [ 'HTTP_HOST' ]; setcookie ( NAME_COOKIE , $username , time () + ( 86400 ), "/" , $cookie_domain ); print $_COOKIE [ NAME_COOKIE ]; The script dies during the print with undefined index error. What am I doing wrong? 回答1: Your lines: setcookie ( NAME_COOKIE , $username , time () + ( 86400 ), "/" , $cookie_domain ); print $_COOKIE [ NAME_COOKIE ]; Whats happening here is that your setting

How do you set a cookie to be accessible across the entire domain in Javascript

匿名 (未验证) 提交于 2019-12-03 03:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I suppose there should be a way to set a cookie to be accessible from the entire domain nevermind from which directory you are setting the cookie. Say in mypage.com/blue/index.php y set the cookie "colour=blue;" this way: document.cookie = "colour" + "=" + "blue" + "; expires=" + expireDate.toGMTString() + "; path=/"; Using this code, the cookie retrieval function in mypage.com/home.php can't access the content of the cookie. If it was just from first level directories that the cookie needs to be set, we would be ok by doing path=../ instead

Keeping the cookie after a cross-domain ajax request

匿名 (未验证) 提交于 2019-12-03 03:04:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: A javascript application running on 10.0.0.1 tries to authenticate it's users with cross-domain ajax calls. The request looks like: function test(again){ $.ajax({ type: 'GET', url: 'http://example.com/userinfo', dataType: 'json', success: function(userinfo){ if(again) test(false);}});} test(true); The first response from the server tries to set a cookie: Access-control-allow-origin:http://10.0.0.1 Set-Cookie:PHPSESSID=uuj599r4k1ohp48f1poobil665; expires=Sat, 28-Jan-2012 17:10:40 GMT; path=/ But the second request does not include this cookie