Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

deleting cookies (perl)

Options
  • 08-01-2002 8:48pm
    #1
    Registered Users Posts: 2,518 ✭✭✭


    I'm trying to work out a way to delete a cookie in perl;

    Basically it's for session management wherby the system remembers if a user has been to the site before but gives them the option to log in as another user (by deleting the cookie set before).

    From reading around I thought that the way to do this in perl was to set the expiration time for the cookie to sometime in the past, but this doesnt seem to be working. Here's what I have so far:
    $user_cookie=cookie(-name => 'usercookie',
    -expires => '-1d');
    print header(-cookie => $user_cookie);

    where 'usercookie' is the cookie that was set beforehand. Changing it's expires attribute to 1 day in the past *should* work, but it doesnt seem to. I've also tried setting expires to 'now' with the same result.


Comments

  • Registered Users Posts: 944 ✭✭✭nahdoic


    Your code looks fine at first glance. Not sure why it's not working (your not passing through the domain name but that shouldn't matter).

    Here's the code i always use, and it always works for me..

    use CGI::Cookie;
    use CGI qw/:standard/;
    $sessionCookie1 = new CGI::Cookie(-name=>'SESSIONID',-value=>"",-domain=>'.whatever.com',-expires => '-14d');
    print header(-cookie=>$sessionCookie1);

    the only other thing I can think of is that you're not realising that the new page has to be loaded with the new header before the cookie is deleted, and you have to make sure you didn't print out any other header before you printed that one to delete the cookie.

    hope that helps ...


Advertisement