jck has asked for the wisdom of the Perl Monks concerning the following question:

The following has been working great for me to allow a logged-in user access to various pages.
use CGI; my $q = new CGI; my $sessid = $q->cookie('SESSID'); if (!$sessid) { print $q->redirect("http://my.domain.com/loginpage/"); exit; } my $cookie = $q->cookie(-name=>"SESSID", -value=> $sessid, -expires => + "+1h"); print $q->header({-type=>"text/html", -charset=>"utf-8", -cookie=>$coo +kie});

I'm modifying a new page, which has a series of links to reload the script with three variables, for year, month and day:

http://my.domain.com/cgi-bin/eventedit?year=2007&month=1&day=9

when i load the script using the link, the sessid ends up undefined, and the page redirects, even though i can see the sessid in the cookie!! does anyone know what's going on?

the thing i don't understand is that i've used this with a lot of other pages, and they work fine...

Replies are listed 'Best First'.
Re: vanishing cookie?
by jettero (Monsignor) on Jan 15, 2007 at 23:05 UTC
    That sure looks like it aught to work to me. The only reasons I can think that it wouldn't are a domain mismatch (eg www.domain.org vs domain.org) or possibly that $sessid is 0, undef, or "", so !sessid tests true by accident.

    -Paul

      jettero - thank you so much!!! it was a domain mismatch!! i inadvertantly added 'www' to the links and i haven't set that on anything else.

      thanks for saving me a lot of headaches (and so quickly!)

      janaki

        It's no problem. Simple errors that you can't see because you're too close are precisely the reason a second set of eyes helps.

        -Paul