#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    84
    Rep Power
    11

    Clearing cookies


    I've got Cookies working fine, keeping track of logged in users on a site, however I am not sure how to delete the cookies if a user wants to log out/user another sign in name. Any help on how I can do this would be great. Thanks in advance
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Posts
    71
    Rep Power
    11
    Hi rebbit.
    In order to delete a cookie you need to set the expires attribute in the
    Set-Cookie header, to date in the past.
    I attached a small class that I use to write/delete cookies.
    It works well on IE and mozzila.
    Hope that helps
    Roy
    Code:
    #!/usr/bin/python
    class my_cookie:
        
        def __init__(self,name,value):
            self.name   = name
            self.value  = value
            self.expire = False
    
        def RenderCookie(self):
            ret = "Set-Cookie: "+self.name+'='+str(self.value)+';Version="1.0"'
            if self.expire == True :
                ret = ret+'; expires="Sat,17 Apr 2000 15:17:17 +0000"'
            return ret
                
        def ExpireCookie(self):
            self.expire = True
    
        def SetValue(self,newVal):
            self.value = newVal
    
        def GetValue(self):
            return self.value
        
        def GetName(self):
            return self.name
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Norway
    Posts
    41
    Rep Power
    11
    Or if you are using the simplecookie module, just set the "max-age" cookie parameter to a negative value.
    Good web hosting info - articles about web hosting
    hb's web dev blog

IMN logo majestic logo threadwatch logo seochat tools logo