Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

deleting cookies (perl)

  • 08-01-2002 08:48PM
    #1
    Registered Users, Registered Users 2 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, Registered Users 2 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