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

Hi

I started to learn CGI::Session and have made some progress thus far.

The below code successfully adds the session data inside a MySQL DB using CGI::Session, however it does not create a cookie. I have no idea where I can start to troubleshoot this problem. It has to do w/ a config setting I'm thinking, because the code seems to work for most other people.
#created the INPUT = New CGI; on previous lines use CGI::Session; my $session = new CGI::Session("driver:MySQL", undef, { Handle => $dbh, DataSource => "DBI:mysql:contrarian:host=my_server", User => "srjiii", Password => $df_pass }); $session->param("member_name", $username); my $cookie = $INPUT->cookie(-name=>'SESSION_Name', -value=>$session->id, -expires=>"+1d"); print $INPUT->header(-cookie=>$cookie);
I read some threads in this website, and it says you must specify a domain name for your cookie? But how come the documentation for the CGI::Session and other examples I have looked at do not say anything about that? I made sure my browser accepts cookies and have looked inside the cookie folder for any cookie named "SESSION_Name" and no luck. What Am I doing wrong? Is it something to do with the code I have or just a config. that I'm not understanding?

IF anyone can tell me some articles/threads that show how you can troubleshoot why your script is not creating a cookie that will be great!

thanks Monks!

Replies are listed 'Best First'.
Re: Troubleshooting Setting a Cookie
by BaldPenguin (Friar) on Jun 13, 2005 at 06:13 UTC
    One thing you might want to try. We use a lot of FireFox for one good reason (at least), a plugin called livehttpheaders. It will show you all headers going in and out of the browser. That will help show what cookie headers are present.

    To my knowledge a domain is not required to be set, however it should be remembered that the domain and path will default to the current value of hostname and the current script's path. So a cookie set from the script www.test.com/perl-bin/setters/cookies.pl will set the domain to 'www.test.com' and the path to '/setters/' requiring any script reading those cookies to be called from the same host and within that path. Try the FireFox plugin and see iof the headers are going through.

    Don
    WHITEPAGES.COM | INC

    Edit by castaway: Closed small tag in signature

Re: Troubleshooting Setting a Cookie
by inman (Curate) on Jun 13, 2005 at 07:49 UTC
    Have a look at node 332844 which covers this issue. Cookies not working as advertised is a common problem.