• cookie


    cookie的重要字段

    [name][value][domain][path][expires][httponly][secure]

    domain默认是本域;

    path默认是目标界面的路径。例如guiqing.com/admin/login.html页面通过javascript来设置一个cookie,那么path值就是/admin/。那么guiqing/other/index.html的界面就无法获得

    guiqing.com/admin/login.html设置的cookie了,除非用iframe

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title>cookieb</title>
    </head>
    <body>
    	<button type="button" onclick="setCookie()">设置cookie</button>
    	<button type="button" onclick="setCookie1()">设置cookie</button>
    	<button type="button" onclick="getCookie()">获取cookie</button>
    	<script>
    		window.onload = function(){
    			var iframeEle = document.createElement("iframe");
    			iframeEle.src = "http://127.0.0.1:8080/cookie1/a.html";
    
    			document.getElementsByTagName('body')[0].appendChild(iframeEle);
    			iframeEle.onload = function(){
    				var childDom = iframeEle.contentDocument || iframeEle.contentWindow.document;
    				alert(childDom.cookie);
    			}
    		}
    		function setCookie(){
    			document.cookie="guiqing=cookieB";
    		}
    		function setCookie1(){
    			document.cookie="guiqing=cookieB1";
    		}
    		function getCookie(){
    			var guiqing = document.cookie;
    			alert(guiqing);
    		}
    	</script>
    </body>
    </html>
    

    httpOnly是指仅在HTTP层面上传输的cookie,客户端脚本就无法读写该cookie了

    secure指的是设置了secure标志的cookie仅在HTTPS层面上安全传输,如果是http的,就不会带上这个cookie。

    本地cookie和内存cookie

    内存cookie在浏览器关掉后就没了

    本地存储主要包括: 本地cookie,localStorage,Flash Cookie

  • 相关阅读:
    thinkphp自动映射分析
    thinkphp自动创建数据对象分析
    html模板输头部出现"&#65279"
    register_shutdown_function 函数详解
    mcrypt加密以及解密过程
    SVN不能解锁,报错:没有匹配的可用锁令牌的解决方法
    微信公众平台JSSDK开发
    PHP的UTF-8中文转拼音处理类
    PHP中文转拼音函数
    php生成mysql数据字典
  • 原文地址:https://www.cnblogs.com/luguiqing/p/8035706.html
Copyright © 2020-2023  润新知