-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetcookieloop.html
More file actions
69 lines (60 loc) · 1.69 KB
/
setcookieloop.html
File metadata and controls
69 lines (60 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function load() {
var count = parseInt(location.search.substr(1));
var i = 0;
var rand = Math.floor(Math.random() * 50);
var inter = setInterval(function() {
if (i > count) {
console.log("DONE! exit");
clearInterval(inter);
var j = 0;
for (let j = 0; j < count; ++j) {
var tmp_name = "name" + j + "rand" + rand;
if (getCookie(tmp_name).length == 0) {
document.getElementById("set_cookie").innerHTML += " " + tmp_name
}
}
}
var name = "name" + i + "rand" + rand;
var value = "val" + i + "rand" + rand;
setCookie(name, value, 5);
console.log("Cookie set " + name + "=" + value);
++i;
document.getElementById("all_cookies").innerHTML = "All cookies: " + document.cookie;
}, 100);
}
function getCookie(cname) {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for(let i = 0; i <ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
function setCookie(cname, cvalue, exdays) {
const d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
let expires = "expires="+ d.toUTCString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
</script>
</head>
<body onload="load()" bgcolor="red">
<div width="100%" height="100%" id="set_cookie">
Missing:
</div>
<div width="100%" height="100%" id="all_cookies" style="font-size:small">
No cookies
</div>
</body>
</html>