On 2/12/06, James.Q.L <shijialist-FFYn/CNdgSA@xxxxxxxxxxxxxxxx> wrote:
> I tried another example and it worked (logged is flushed)..
> % perl -MCGI::Session -e '{my $s=CGI::Session->new();$s->param("logged",1)}'
>
> I am posting my code here and hopefully someone can spot why it doesn't flush
> in the login
> subroutine.
Nothing in the code you posted suggests any problems. So it must be
somewhere else in the code. Do you by chance pass the $self->session
object to your template? I believe that HTML::Template sometimes
hangs on to the parameters that you send to it, and hence the Session
object doesn't go out of scope (that is a wild guess btw)
You can use Devel::Peek to double check the reference count of your variables:
perl -MDevel::Peek=Dump -e 'my $x=10; Dump $x; my $y=\$x; Dump $x; Dump $y'
Look at the value of REFCNT and how it changes when we store a
reference to $x in $y.
Since you are using CGI::Application, you can probably just setup a
'teardown' or 'cgiapp_postrun' method that looks at the REFCNT of the
session object.
### UNTESTED CODE ###
sub teardown {
my $self = shift;
my $session = $self->session;
use Devel::Peek qw(Dump);
print STDERR "Peeking at \$self->session\n----------\n";
Dump ($session);
print STDERR "----------\n";
}
Then check your error log and see the REFCNT value. If it is more
than 2, then you have a problem somewhere in your code (there are
already at least 2 copies, since $self has a copy, and you just made a
fresh copy in $session). Although this might indicate that you have a
problem, it doesn't give you any indication where the problem is in
your code...
> another question along with the code: in the login sub, if user passes the
> authentication then
> calls session method which will create new session and send cookie(since i
> have SEND_COOKIE on),
> user will then be redirect to ./ . I am expecting a new cookie will be
> created when it is
> redirecting user to ./ but i don't see any cookie in the response header.
> therefor my script
> can't recognize the user as a logged in one. what's wrong in the code?
Try it again without the 'domain' and 'path' options to the cookie. I
find that those two often keep cookies from being set correctly in the
browser (actually, to be more acurate, they are set correctly in the
browser, but the browser doesn't send them back on the next request).
You might also increase the expiry time while testing this. Also,
make sure that the cookie is actually being sent to the browser in the
first place (using something like the livehttpheaders plugin for
mozilla makes this really easy).
Cheers,
Cees
-------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc. Do you grep through log files
for problems? Stop! Download the new AJAX search engine that makes
searching your log files as easy as surfing the web. DOWNLOAD SPLUNK!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid3432&bid#0486&dat1642
|
Try Searching:
servers, voip, java, networking, microsoft ...
|
|
|
|