The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 2,392 other followers

Every site should have a script like web.archive.org/__cleancookies__.html

Posted by jpluimers on 2021/06/02

I run in too many sites that keep creating new cookies, but never delete the old ones, ultimately leading to 5xx errors.

Every site should have a page like [WayBack] web.archive.org/cleancookies.html that cleans non-current cookies.

So I copied toe source to [WayBack] Copy of https://web.archive.org/cleancookies.html · GitHub for inspiration to look at.

–jeroen

<html>
<body>
<script type="text/javascript">
var DONT_DELETE = {
"logged-in-sig": 1,
"logged-in-user" : 1,
};
var cookies = document.cookie.split(/; */);
var result = {};
var cookie_count = 0;
for (var i = 0; i < cookies.length; i++) {
var kv = cookies[i].split(/=/);
if (kv.length >= 2) {
var name = kv[0];
if (DONT_DELETE[name]) {
result[name] = { action:'kept' };
} else {
document.cookie = name + "=; domain=.archive.org; path=/; max-age=0";
document.cookie = name + "=; domain=web.archive.org; path=/; max-age=0";
document.cookie = name + "=; path=/; max-age=0";
result[name] = { action: 'deleted' };
cookie_count++;
}
}
}
cookies = document.cookie.split(/; */);
for (i = 0; i < cookies.length; i++) {
var kv = cookies[i].split(/=/);
if (kv.length >= 2) {
result[kv[0]].still_there = true;
}
}</script>
<div>Done.</div>
<script type="text/javascript">
if (cookie_count > 0) {
document.write("<ul>");
for (name in result) {
var r = result[name];
if (r.action == 'kept') {
document.write("<li><code>" + name + "</code> (kept)</li>");
} else if (r.still_there) {
document.write("<li><code>" + name + "</code> (could not delete)</li>");
} else {
document.write("<li><code>" + name + "</code> (deleted)</li>");
}
}
document.write("</ul>");
} else {
document.write("<div>You had no cookies to delete. Hooray!</div>");
}
</script>
</body>
</html>

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

 
%d bloggers like this: