> Hi Roy
>
>
> $cookie = $q->cookie(-name=>'ID', -value=>"$ID", -expires =>
> "-1d", -path=>'/');
>
> I think if you set the expires value to "-1d" you are telling the
> cookie it has
> expired. I would guess that if the cookie was not already set the
> browserO would
> not bother to set one just to expire it. Try "+1d" assuming that
> this isn't a
> typo ;-)
>
> my $new_url = $q->url(-full=>1) . '?action=client_main';
> $self->header_type('redirect');
> $self->header_props(-cookie => $cookie, -url=> $new_url);
> my $output = "Redirect $new_url";
> return $output;
>
> Hang on I'm just digging out my source code ...
>
> OK, here's my sub which authenticates a user and sets a cookie (user
> authentication is just here for testing):
>
> sub process_login
> {
> my $self = shift;
> my $query = $self->query(); # Get the
> Query object
> my $dbh = $self->param('dbh'); # Get the db
> handle (Connect is
> done in setup() )
> my $new_url = $query->url(-full=>1) . "?rm=show_page"; #
> Get our URL for
> redirect
> my ($uname, $fullname, $email, $password) =
> $dbh->selectrow_array("SELECT
> username, fullname, email, password FROM users WHERE username=?;", undef,
> $query->param('uname') );
>
> # This is a simple check for testing. Obviously we need to
> add encrypted
> password checks!
> if ( ! $uname ){
> $self->param('login_message', 'Invalid login');
> return $self->show_page();
> } else {
> # Set cookie
> my %cookie_values = (login => $uname,
> email => $email,
> name => $fullname
> );
>
> my $cookie = new CGI::Cookie(-name => 'techweb',
>
> -value =>
> \%cookie_values,
>
> -expires =>
> '+1h',
> );
>
> $self->header_type('redirect');
> $self->header_props( -cookie => $cookie,
> -url => $new_url
> );
> }
> }
>
> This sub is a run mode of my application and is called when the
> submit button on
> my login form is pressed. AFAIK you can set scalar data in the
> cookie by using
> -value => 'My scalar value' insted of the hash reference.
>
> If you set hash data remember to retrieve it as a hash and not a
> scalar as this
> is what was causing my original problem :-)
>
> Hope this helps.
>
> Best Regards
>
> Paul
>
>
Thanks Paul. I am still having some problems though. Any chance of the
problems being that the server executing the code is IIS?
The following doesn't work (cookie isn't set):
my $new_url = $q->url(-full=>1) . '?action=client_main';
my %cookie_values = (login => "1", email => "2", name=> "3");
my $cookie = new CGI::Cookie(-name => 'techweb',-value =>
\%cookie_values, -expires => '+1h');
$self->header_type('redirect');
$self->header_props( -cookie => $cookie, -url=> $new_url);
The following code does work (there is no redirect):
my $new_url = $q->url(-full=>1) . '?action=client_main';
my %cookie_values = (login => "1", email => "2", name=> "3");
my $cookie = new CGI::Cookie(-name => 'techweb',-value =>
\%cookie_values, -expires => '+1h');
$self->header_props(-cookie=>$cookie);
return "done!";
I am not sure what I am doing wrong. Any further help will be appreciated.
Roy
---------------------------------------------------------------------
Web Archive: http://www.mail-archive.com/suppressed/
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed
Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.