• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Deleting a Cookie

 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I want to remove a specific cookie but I can't quite seem to get it to work. I know that you can't really "delete" a cookie, but I should be able to set the expiration date to some time in the past, causing it to be deleted by the browser, right?

Anyone have a snippet of code that will do just that? In this case, I don't really care if I delete all the cookies for the site or just one specific cookie. I know the name of the cookie that I want to delete (let's just say that cookie is named "token") but, if it's easier to delete them all, I'm fine with that, as well.

Thanks, folks,
Corey
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From page 224 of my book:



Hope this helps!
Eric
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, Eric - that's just what I was looking for...except that it's not bloody working!

Like I said, I've got a number of cookies. Your functions work great and I can delete any of them except the one that I really want to delete. For some reason, the get() function seems to get all fouled up when I look for the one cookie that I want to get rid of. In that case, startC is set to 55, but this line:



results in endC being set to 10! How the heck does that happen? Needless to say, when the substring line is invoked from 55 to 10, you end up with an emprty String.

Any ideas on why that's happening? As a side note - the cookie I'm trying to delete seems to have a disgustingly long value. I don't know if that's fouling things up or not.
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you do this for me..

go into your application, and where you want to run this delete this cookie value paste the following line into the address bar:

javascript:document.write(document.cookie);

can you then paste that here so I can recreate the cookie here and see if I can recreate your problem!

Eric
[ February 24, 2005: Message edited by: Eric Pascarello ]
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I figured you'd ask for something like that. Well, here ya go...

test=test2; JSESSIONID=00009smLHPo_rYYXD5R52ttI4jc:-1; LtpaToken=i+6u9JEwcpzEnMCuU97mivZ5Nl6H6PSUr40soEBdPgqH0S4ONcUJ11DPe
J+/1+l5Xas3eyJn3W+Sv9QxvuKhW9B3g0Hym80iFnuakDy2Xfybsk3YqFbjANyJ3fh+
KJE5gH2WTTGKkP7JrgFcs31otGZdVYaq0LqnJ5oIqY0lkNmlifRH5eMNuIiK/9r4+bz
3qpedVWj55o42jPyisJQTbYZIcTW0+4Bw/b7zbpDk76hcmPIXua1HBkse9UGuXK4Pxv
K3Qjnr0HBxv2amjh1uXQtr5q4jHqn6Ael6tZZuuR4yDn0EQLQGzgsw1dxwRTaHIYrbM
LUV5SxqcSCmZzPlanMRMAiucLWYDdBRuv9hLouJEDTqFtSBCA==

Note that the final 5 lines of that are really just a continuation of the LtpaToken cookie value - I added line breaks in order to preserve the formatting here on the ranch. It's that LtpaToken cookie that has just a disturbingly long value and that's the one I want to get rid of.

Thanks, Eric.
[ February 25, 2005: Message edited by: Corey McGlone ]
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I will play with it and see what I can come up with...
 
Eric Pascarello
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I ran this and it seemed to work, maybe it has some problem with the sever side?



(Added breaks to long string)

Eric

[ February 25, 2005: Message edited by: Eric Pascarello ]
[ February 25, 2005: Message edited by: Eric Pascarello ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic