Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #18240 > unrolled thread

Why is it not possible to remove a session cookie with this code

Started by"Tony" <tony.johansson@inport.com>
First post2013-01-23 16:57 +0100
Last post2013-01-26 16:18 -0800
Articles 4 — 3 participants

Back to article view | Back to comp.lang.javascript


Contents

  Why is it not possible to remove a session cookie with this code "Tony" <tony.johansson@inport.com> - 2013-01-23 16:57 +0100
    Re: Why is it not possible to remove a session cookie with this code "Tony" <tony.johansson@inport.com> - 2013-01-25 15:37 +0100
      Re: Why is it not possible to remove a session cookie with this code Gene Wirchenko <genew@telus.net> - 2013-01-25 09:41 -0800
    Re: Why is it not possible to remove a session cookie with this code Arty Effem <ignoring@mail.com> - 2013-01-26 16:18 -0800

#18240 — Why is it not possible to remove a session cookie with this code

From"Tony" <tony.johansson@inport.com>
Date2013-01-23 16:57 +0100
SubjectWhy is it not possible to remove a session cookie with this code
Message-ID<kdr7c0$lsa$1@dont-email.me>
I create a cookie  by using writeCookie function and I read the cookie by 
using the readCookie function. You can see the functions below.
This works good and I use IE 10
Now I want to remove the session cookie without having to close down the 
browser and I use function deleteCookie.
The problem is that if I delete an existing cookie by using deleteCookie 
function and then read the cookie by using readCookie the cookie
is still existing despite having tried to delete it.
Can anybody help me with that ?

function deleteCookie(key)
{
   document.cookie = key + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}

function writeCookie(name, value)
{
    document.cookie = name + "=" + value + "; path=/";
}

and I read the cookie by using this function
function readCookie(name)
{
    var i, c, ca, nameEQ = name + "=";
    ca = document.cookie.split(';');
    for (i = 0; i < ca.length; i++)
    {
        c = ca[i];
        while (c.charAt(0) == ' ')
        {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) == 0)
        {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return '';
}

//Tony 

[toc] | [next] | [standalone]


#18249

From"Tony" <tony.johansson@inport.com>
Date2013-01-25 15:37 +0100
Message-ID<kdu5aj$qpu$1@dont-email.me>
In reply to#18240
I found a solution on the net.

//tony

"Tony"  wrote in message news:kdr7c0$lsa$1@dont-email.me... 

I create a cookie  by using writeCookie function and I read the cookie by 
using the readCookie function. You can see the functions below.
This works good and I use IE 10
Now I want to remove the session cookie without having to close down the 
browser and I use function deleteCookie.
The problem is that if I delete an existing cookie by using deleteCookie 
function and then read the cookie by using readCookie the cookie
is still existing despite having tried to delete it.
Can anybody help me with that ?

function deleteCookie(key)
{
   document.cookie = key + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}

function writeCookie(name, value)
{
    document.cookie = name + "=" + value + "; path=/";
}

and I read the cookie by using this function
function readCookie(name)
{
    var i, c, ca, nameEQ = name + "=";
    ca = document.cookie.split(';');
    for (i = 0; i < ca.length; i++)
    {
        c = ca[i];
        while (c.charAt(0) == ' ')
        {
            c = c.substring(1, c.length);
        }
        if (c.indexOf(nameEQ) == 0)
        {
            return c.substring(nameEQ.length, c.length);
        }
    }
    return '';
}

//Tony 

[toc] | [prev] | [next] | [standalone]


#18251

FromGene Wirchenko <genew@telus.net>
Date2013-01-25 09:41 -0800
Message-ID<upg5g85n30pfoio8iitfg42ufqvmf38ri6@4ax.com>
In reply to#18249
On Fri, 25 Jan 2013 15:37:05 +0100, "Tony" <tony.johansson@inport.com>
wrote:

>I found a solution on the net.

     So post it here.

[snip]

Sincerely,

Gene Wirchenko

[toc] | [prev] | [next] | [standalone]


#18273

FromArty Effem <ignoring@mail.com>
Date2013-01-26 16:18 -0800
Message-ID<6778b20a-9efb-48ec-aafd-889b5d3fd2aa@googlegroups.com>
In reply to#18240
On Wednesday, 23 January 2013 15:57:00 UTC, Tony  wrote:
> I create a cookie  by using writeCookie function and I read the cookie by 
> 
> using the readCookie function. You can see the functions below.
> 
> This works good and I use IE 10
> 
> Now I want to remove the session cookie without having to close down the 
> 
> browser and I use function deleteCookie.
> 
> The problem is that if I delete an existing cookie by using deleteCookie 
> 
> function and then read the cookie by using readCookie the cookie
> 
> is still existing despite having tried to delete it.
> 
function deleteCookie(key)
{
   document.cookie = key + "=;expires=Thu, 01 Jan 1970 00:00:00 GMT";
}

function writeCookie(name, value)
{
    document.cookie = name + "=" + value + "; path=/";
} 

writeCookie hard codes the path setting but the deleter doesn't, so unless you're on /, it can't delete the cookie.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web