[cgiapp] Using CGI::Cookie from inside CGI::Application

2008-05-21 Thread CGI User

Hello,

I'm trying to use CGI::Cookie module calling it from CGI::Application 
environment in cgiapp_prerun like this:


sub cgiapp_prerun {
my $self = shift;

my $cookie = CGI::Cookie-new(
-name   = 'some_name',
-value  = '12345',
-domain = '.come_domain.com',
-path   = '/',
-expires= '+1H',
-secure = 1,
);

$self-header_add(-cookie = [$cookie]);

return $self;
}

But nothing is happening, and this test cookie is not being set in the browser 
(Firefox).


However, when I try to do this:

sub cgiapp_prerun {
my $self = shift;

my $q = $self-query();

my $cookie = $q-cookie('some_name' = '12345');

   $self-header_add(-cookie = [$cookie]);

return $self;
}

It works and the cookie name and its value is being set in the browser.

My question are:
1. Why it didn't work in the first case.
2. If the first case won't work, then how I can set all the cookie parameters
e.g. domain, path, expires, secure using the second case.
3. How I can retrieve my cookie from the browser is the recommended first case 
to set cookie is not working, and the second case is working but I cannot see 
any method to retrieve my own cookie?


Thank you very much in advance.

Alex

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Using CGI::Cookie from inside CGI::Application

2008-05-21 Thread Alexandr Ciornii
Hello!

1. Replace '+1H' with '+1h'
2. Are you using https connection? You need to, if you are using
'secure' cookie.

You can see which headers are sent with 'Live HTTP headers' extension
for Firefox.

As for retrieving cookie values, look at CGI.pm documentation: To
retrieve a cookie, request it by name by calling cookie() method
without the -value parameter. Use  my $value=$q-cookie('some_name'
);

2008/5/21 CGI User [EMAIL PROTECTED]:
 I'm trying to use CGI::Cookie module calling it from CGI::Application
 environment in cgiapp_prerun like this:

 sub cgiapp_prerun {
my $self = shift;

my $cookie = CGI::Cookie-new(
-name   = 'some_name',
-value  = '12345',
-domain = '.come_domain.com',
-path   = '/',
-expires= '+1H',
-secure = 1,
);

$self-header_add(-cookie = [$cookie]);

return $self;
 }

 But nothing is happening, and this test cookie is not being set in the
 browser (Firefox).

 My question are:
 1. Why it didn't work in the first case.
 2. If the first case won't work, then how I can set all the cookie
 parameters
 e.g. domain, path, expires, secure using the second case.
 3. How I can retrieve my cookie from the browser is the recommended first
 case to set cookie is not working, and the second case is working but I
 cannot see any method to retrieve my own cookie?

-- 
Alexandr Ciornii, http://chorny.net

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Using CGI::Cookie from inside CGI::Application

2008-05-21 Thread CGI User

Hi Sasha,
Thanks for the hints.
However, even if I replace '+1H' with '+1h' and don't set secure flag
the cookie still doesn't show up in the browser.

Do you have any other ideas?
Thanks in advance,

Alex


Alexandr Ciornii wrote:

Hello!

1. Replace '+1H' with '+1h'
2. Are you using https connection? You need to, if you are using
'secure' cookie.

You can see which headers are sent with 'Live HTTP headers' extension
for Firefox.

As for retrieving cookie values, look at CGI.pm documentation: To
retrieve a cookie, request it by name by calling cookie() method
without the -value parameter. Use  my $value=$q-cookie('some_name'
);

2008/5/21 CGI User [EMAIL PROTECTED]:

I'm trying to use CGI::Cookie module calling it from CGI::Application
environment in cgiapp_prerun like this:

sub cgiapp_prerun {
   my $self = shift;

   my $cookie = CGI::Cookie-new(
   -name   = 'some_name',
   -value  = '12345',
   -domain = '.come_domain.com',
   -path   = '/',
   -expires= '+1H',
   -secure = 1,
   );

   $self-header_add(-cookie = [$cookie]);

   return $self;
}

But nothing is happening, and this test cookie is not being set in the
browser (Firefox).



My question are:
1. Why it didn't work in the first case.
2. If the first case won't work, then how I can set all the cookie
parameters
e.g. domain, path, expires, secure using the second case.
3. How I can retrieve my cookie from the browser is the recommended first
case to set cookie is not working, and the second case is working but I
cannot see any method to retrieve my own cookie?





#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Using CGI::Cookie from inside CGI::Application

2008-05-21 Thread Alexandr Ciornii
Hello.

1. Try removing
   -domain = '.come_domain.com',
in addition to other changes.
2. Try removing all except '-name',  '-value', '-expires' parameters.
and make expires bigger like '+20h'.


2008/5/21 CGI User [EMAIL PROTECTED]:
 Hi Sasha,
 Thanks for the hints.
 However, even if I replace '+1H' with '+1h' and don't set secure flag
 the cookie still doesn't show up in the browser.

-- 
Alexandr Ciornii, http://chorny.net

#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Using CGI::Cookie from inside CGI::Application

2008-05-21 Thread Rhesa Rozendaal

CGI User wrote:

My question are:
1. Why it didn't work in the first case.
2. If the first case won't work, then how I can set all the cookie parameters
e.g. domain, path, expires, secure using the second case.
3. How I can retrieve my cookie from the browser is the recommended first case 
to set cookie is not working, and the second case is working but I cannot see 
any method to retrieve my own cookie?




CGI::Cookie and CGI-cookie (sorry :) have the same interface, and they should 
produce the same results:


use strict;
use warnings;

use Test::More tests = 1;

$ENV{CGI_APP_RETURN_ONLY} = 1;

my $m = My::App-new;
$m-start_mode('q_cookie');
my $q_out = $m-run;
diag $q_out;

$m = My::App-new;
$m-start_mode('cgi_cookie');
my $cgi_out = $m-run;
diag $cgi_out;

is $q_out, $cgi_out, headers are identical;


package My::App;

use base qw/CGI::Application/;

sub setup {
my $self = shift;
$self-run_modes( [ qw/ cgi_cookie q_cookie / ] );
}

sub q_cookie {
my $self = shift;
my $q= $self-query;
my $cookie = $q-cookie(
-name   = 'some_name',
-value  = '12345',
-domain = '.come_domain.com',
-path   = '/',
-expires= '+1h',
-secure = 1,
);

$self-header_add(-cookie = [$cookie]);

return '';
}

sub cgi_cookie {
my $self = shift;
my $cookie = CGI::Cookie-new(
-name   = 'some_name',
-value  = '12345',
-domain = '.come_domain.com',
-path   = '/',
-expires= '+1h',
-secure = 1,
);

$self-header_add(-cookie = [$cookie]);
return '';
}

__END__
1..1
# Set-Cookie: some_name=12345; domain=.come_domain.com; path=/; expires=Wed, 
21-May-2008 22:51:04 GMT; secure

# Date: Wed, 21 May 2008 21:51:03 GMT
# Content-Type: text/html; charset=ISO-8859-1
#
# Set-Cookie: some_name=12345; domain=.come_domain.com; path=/; expires=Wed, 
21-May-2008 22:51:04 GMT; secure

# Date: Wed, 21 May 2008 21:51:03 GMT
# Content-Type: text/html; charset=ISO-8859-1
#
ok 1 - headers are identical


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Using CGI::Cookie from inside CGI::Application

2008-05-21 Thread CGI User

Thank you,
I got it.

If I form cookie like this:
my $cookie = $q-cookie( -name=$cook_name, -value=$sess_id, 
-expires=$cook_exp);

$self-header_add(-cookie = $cookie);

Everything works honky dory.

But if I form cookie like this:
my $cookie = $q-cookie( -name=$cook_name, -value=$sess_id, 
-expires=$cook_exp, -domain='.'.$domain, -path='/');


It doesn't work at all.

I wonder to know why and how I can set at least domain into cookie.
In the CGI.pm pod I clearly read this:

The interface to HTTP cookies is the cookie() method:

$cookie = cookie(-name='sessionID',
 -value='xyzzy',
 -expires='+1h',
 -path='/cgi-bin/database',
 -domain='.capricorn.org',
 -secure=1);
print header(-cookie=$cookie);


Then why there is such a discrepancy between my practical case and CGI.pm pod?
Go figure ...

Alex




Alexandr Ciornii wrote:

Hello.

1. Try removing
   -domain = '.come_domain.com',
in addition to other changes.
2. Try removing all except '-name',  '-value', '-expires' parameters.
and make expires bigger like '+20h'.


2008/5/21 CGI User [EMAIL PROTECTED]:

Hi Sasha,
Thanks for the hints.
However, even if I replace '+1H' with '+1h' and don't set secure flag
the cookie still doesn't show up in the browser.





#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####




Re: [cgiapp] Using CGI::Cookie from inside CGI::Application

2008-05-21 Thread Michael Peters
CGI User wrote:

 But if I form cookie like this:
 my $cookie = $q-cookie( -name=$cook_name, -value=$sess_id,
 -expires=$cook_exp, -domain='.'.$domain, -path='/');
 
 It doesn't work at all.

What is the domain you are using to access this? If it's www.domain.tld then
you're good. But if it's just domain.tld then you aren't. Using the string
.domain.tld means any domain *under* this one, but not including this one.
Try just using domain.tld instead since it means this domain and any under 
it.

-- 
Michael Peters
Plus Three, LP


#  CGI::Application community mailing list  
####
##  To unsubscribe, or change your message delivery options,  ##
##  visit:  http://www.erlbaum.net/mailman/listinfo/cgiapp##
####
##  Web archive:   http://www.erlbaum.net/pipermail/cgiapp/   ##
##  Wiki:  http://cgiapp.erlbaum.net/ ##
####