Newbie help - My cookies won't bake?

2002-03-08 Thread Jeff Armstrong

Revered Chefs,

Please forgive a mere mod_perl kitchen-hand, undergoing early cookie 
training... I have the following cookie code, but no cookies come 
back when I refresh, and I don't see any $HTTP_COOKIE in %ENV. 
$cookies ends up as a hash ref pointing to an empty hash.

I have the following in my httpd.conf:
  PerlWarn On
  PerlTaintCheck On
  PerlFreshRestart On
  PerlInitHandler Apache::Reload
  PerlSetVar ReloadAll On
  Files *.pl
SetHandler perl-script
PerlHandler Apache::Registry
PerlSendHeader Off
Options +ExecCGI
  /Files


Help?? TIA

Jeff

# As you will note, this highly original recipe was lifted unchanged 
# from Delia Smith's 'How to Boil Eggs for Breakfast'.
#
# This is the cookie dough that don't want to bake
use strict;
require dumpvar.pl;
use Apache;
use Apache::Cookie;

# read in the cookie if this is an old session
my $r = Apache-request();
my $cookies = Apache::Cookie-fetch;

my $sent = '';
if (!$cookies-{foo} ) {
  $sent = 'sending cookie';
  my $cookie = Apache::Cookie-new(
  $r,
  -name=  'foo',
  -value   =  'bar',
  -expires =  '+1D',
  -domain  =  undef,
  -path=  '/',
  -secure  =  undef,
 );
  
  $cookie-bake;
} else {
  $sent = 'received cookie';
}
$r-content_type(text/html);
$r-send_http_header;

print $0 $sent, HR;
main::dumpValue(\$cookies);
print HR, $r-as_string, HR;
map { print nbsp;nbsp;$_ = '$ENV{$_}' BR\n; } sort keys %ENV;
#





Re: Newbie help - My cookies won't bake?

2002-03-08 Thread Geoffrey Young

Jeff Armstrong wrote:
 
 Revered Chefs,
 
 Please forgive a mere mod_perl kitchen-hand, undergoing early cookie
 training... I have the following cookie code, but no cookies come
 back when I refresh, and I don't see any $HTTP_COOKIE in %ENV.
 $cookies ends up as a hash ref pointing to an empty hash.
 

your approach seems a bit wrong.  try looking over these two recipes

http://www.modperlcookbook.org/code/ch03/Cookbook/GetCookie.pm
http://www.modperlcookbook.org/code/ch03/Cookbook/SetCookie.pm

HTH

--Geoff



Re: Help with cookies

2001-08-09 Thread Mark Maunder

If you're chaining handlers, they should all return OK. They will all get
called, so long as they either appear in the config file on the same line, or
have been registered using $r-push_handlers().

One of them must send the header though, or return REDIRECT (for example) to
perform a redirect. Does Apache::Cookie-bake() set both the regular headers and
the error headers?

I usually call the header setting routines manually like so:
$r-header_out(Set-Cookie = $cookie-as_string()); #and also call
$r-err_header_out(Set-Cookie = $cookie-as_string());

If you're returning OK, the server assumes you handled the request. So you
should have sent a response page and would probably have used
$r-send_http_header to generate the header for that page.
If you return REDIRECT, the header is sent for you based on what you set with
$r-err_header_out(). So if you want to be sure that the cookie will be set, you
should set it in both the error headers and the regular headers.

Then depending on whether you're redirecting or just generating a page call:
return REDIRECT;
 Or call
$r-send_http_header('text/html'); #If you're about to send some HTML.

Either way the cookie gets sent. (The err_header_out is for the REDIRECT and the
header_out is for the regular send_http_header). Also remember to set the
Location header if you're doing a redirect. I also use both err_header_out AND
header_out to set this. (I should probably just be using err_header_out for
that).

~mark.




Robert Landrum wrote:

 At 3:50 PM -0400 8/8/01, Perrin Harkins wrote:
 
 It depends on what's happening in that second module.  If you don't send an
 actual response to the client, headers (including cookies) will not be sent
 out.

 Umm... Is

return OK;

 the correct thing to return when using multiple handlers?  I thought
 DECLINED was the correct status code.  Then the last module (in this
 case MIS_APPS::RHS::Control::Scan) would return OK.

 Robert Landrum

 --
 A good magician never reveals his secret; the unbelievable trick
 becomes simple and obvious once it is explained. So too with UNIX.

--
Mark Maunder
Senior Architect
SwiftCamel Software
http://www.swiftcamel.com
mailto:[EMAIL PROTECTED]





Help with cookies...

2001-08-08 Thread Rasoul Hajikhani

Can some one tell me why I can not set a cookie...
I have a module that is supposed to set a cookie called Cookie_Check:

package MIS_APPS::RHS::Control::Cookie_Check;

use Apache::Constants qw(:common);
use Apache::Request;

use Apache::Cookie ();

use strict;

sub handler
{
my $r   = shift;

$res= Apache::Cookie-new( $r,
 -name  
='randh_webuname',
 -value  =
$webuname,
 -domain =
'.rhythm.com',
 -expires=
'+24H',
 -path   =
'/'
 )-bake;
return OK;
}
1;

And after my second handler should kick in and do some other magic. In
my httpd.conf I have:

Location /scan
SetHandler perl-script
PerlHandler MIS_APPS::RHS::Control::Cookie_Check
MIS_APPS::RHS::Control::Scan

AuthName RHS
AuthType Basic
AuthUserFile /etc/passwd
require valid-user
/Location

But I never get to set the cookie... Can someone tell me what I am doing
wrong?
Thanks in advance
-r



Help with cookies

2001-08-08 Thread Rasoul Hajikhani

Can some one tell me why I can not set a cookie...
I have a module that is supposed to set a cookie called Cookie_Check:

package MIS_APPS::RHS::Control::Cookie_Check;

use Apache::Constants qw(:common);
use Apache::Request;

use Apache::Cookie ();

use strict;

sub handler
{
my $r   = shift;

$res= Apache::Cookie-new( $r,
 -name  
='randh_webuname',
 -value  =
$webuname,
 -domain =
'.rhythm.com',
 -expires=
'+24H',
 -path   =
'/'
 )-bake;
return OK;
}
1;

And after my second handler should kick in and do some other magic. In
my httpd.conf I have:

Location /scan
SetHandler perl-script
PerlHandler MIS_APPS::RHS::Control::Cookie_Check
MIS_APPS::RHS::Control::Scan

AuthName RHS
AuthType Basic
AuthUserFile /etc/passwd
require valid-user
/Location

But I never get to set the cookie... Can someone tell me what I am doing
wrong?
Thanks in advance
-r



Re: Help with cookies

2001-08-08 Thread Robert Landrum

At 3:50 PM -0400 8/8/01, Perrin Harkins wrote:

It depends on what's happening in that second module.  If you don't send an
actual response to the client, headers (including cookies) will not be sent
out.

Umm... Is

   return OK;

the correct thing to return when using multiple handlers?  I thought 
DECLINED was the correct status code.  Then the last module (in this 
case MIS_APPS::RHS::Control::Scan) would return OK.

Robert Landrum

--
A good magician never reveals his secret; the unbelievable trick
becomes simple and obvious once it is explained. So too with UNIX. 



Re: Help with cookies

2001-08-08 Thread Perrin Harkins

 Long time no hear... I heard you moved to NY...

This is true.  I'm exploring new territory.

 I think I do send a response back to Apache! I
 mean I return OK status. Or do you mean something else? Like
 $r-header_out(...)?

You need to send the headers (with $r-send_http_header or something
similar), and print something to the client.  Otherwise, your Set-Cookie
header will never get sent out.

Glad to see you're still mod_perl-ing.

- Perrin




Re: Help with cookies

2001-08-08 Thread Perrin Harkins

 Umm... Is

return OK;

 the correct thing to return when using multiple handlers?

Yes, according the mod_perl docs.  It only stops if you return something
other than OK or DECLINED.

- Perrin




Re: Help with cookies

2001-08-08 Thread Alastair

On Wed, Aug 08, 2001 at 12:21:07PM -0700, Rasoul Hajikhani wrote:
 But I never get to set the cookie... Can someone tell me what I am doing
 wrong?

As Perrin, said, is a cookie header being set and sent somewhere else in
the code? In my experience, cookie programming can be extremely
frustrating, given the different browsers in use for instance.
Sometime's it's best to start very simple and work up from there.

I've been using CGI::Cookie with some success recently but I'd expect
Apache::Cookie to work in a similar way.

Good luck!


-- 
Alastair| 
[EMAIL PROTECTED]   |
http://www.calliope.demon.co.uk |PGP Key : A9DE69F8
---