Re: cgi-script to handler communication [MP2]

2003-01-17 Thread Vishal Verma
On Thu, 2003-01-16 at 20:51, Stas Bekman wrote:
 Vishal Verma wrote:
  I am implementing a login/logout mechanism. The user can't access any
  page till he logs in. That is any attempt to access pages without
  logging in will be redirected to the login screen. I have successfully
  implemented this part. The login page is generated by a CGI script. Once
  the user logs in successfully, I want to set a cookie. That's the reason
  why I want the login CGI script to pass the result to my handler. The
  handler, which must be run after the CGI script has been run, will
  decide to modify the output header (to set cookie) depending upon the
  result code passed to it by the login screen.
 
 I don't understand why don't you do that in your cgi script (btw, is it 
 running under mod_perl/registry or just mod_cgi?). Why do you need yet 
 another handler?

Basically, I want to keep all the login/logoff logic in one place -
.i.e. mod_perl handlers. My script is running under mod_perl.

 If it's a mod_perl registry script, you have an access to the request 
 object. Either via my $r = shift; at the beginning of your script or via 
 Apache-request (which retrieves the globally stored req object)

This worked!

thanks
-vish




cgi-script to handler communication

2003-01-16 Thread Vishal Verma
Hi,

I have two questions:

a. How can I communicate a value from my cgi-script to a mod_perl
handler. I know you can pass values from handlers to cgi-scripts using
$r-args and environment variables. But, what if I want to pass a value
from the cgi-script to a handler? It's obvious that the handler should
get called after the cgi-script gets executed. 

b.Also, I don't know of any handler that gets called after the content
has been generated. PerlOutputFilterHandler is not what I want, because,
there I have to read and manually 'print' all the output using
$filter-print. If PerlOutputFilterHandler is the only option, then, can
I modify the output headers in it?

thanks
-vish




Re: cgi-script to handler communication

2003-01-16 Thread Stas Bekman
[Please mention mp2 in the subject/body of the message so we don't have to 
guess what version you are talking about]

a. How can I communicate a value from my cgi-script to a mod_perl
handler. I know you can pass values from handlers to cgi-scripts using
$r-args and environment variables. But, what if I want to pass a value
from the cgi-script to a handler? It's obvious that the handler should
get called after the cgi-script gets executed. 

You don't detail what kind of handler you are talking about. But look at 
notes/pnotes (search perl.apache.org for examples), which are useful for 
passing data around.

b.Also, I don't know of any handler that gets called after the content
has been generated. PerlOutputFilterHandler is not what I want, because,
there I have to read and manually 'print' all the output using
$filter-print. If PerlOutputFilterHandler is the only option, then, can
I modify the output headers in it?


Looks like you are a bit confused with 'handlers'. You may want to read 
the handler chapters at http://perl.apache.org/docs/2.0/user/index.html

You can insert several handlers (for each phase) using push_handlers or 
using the configuration file. Depending on the phase's behavior described 
here:
http://perl.apache.org/docs/2.0/user/handlers/intro.html#Single_Phase_s_Multiple_Handlers_Behavior
only the first handler returning OK (or error) or all of the handlers will 
be run.

And yes, you can modify output headers in PerlOutputFilterHandler, if the 
filter is a connection filter. Here is an example that does that for input 
headers, but will work the same for the output handlers:
http://perl.apache.org/docs/2.0/user/handlers/filters.html#Connection_Input_Filters

Though it's probably not as fast as adjusting the headers via the api in 
the response handlers. However since you aren't telling what you are 
trying to do I can't give you a better advice.

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com



Re: cgi-script to handler communication [MP2]

2003-01-16 Thread Vishal Verma
 Though it's probably not as fast as adjusting the headers via the api in 
 the response handlers. However since you aren't telling what you are 
 trying to do I can't give you a better advice.

Here's what I'm trying to do:

I am implementing a login/logout mechanism. The user can't access any
page till he logs in. That is any attempt to access pages without
logging in will be redirected to the login screen. I have successfully
implemented this part. The login page is generated by a CGI script. Once
the user logs in successfully, I want to set a cookie. That's the reason
why I want the login CGI script to pass the result to my handler. The
handler, which must be run after the CGI script has been run, will
decide to modify the output header (to set cookie) depending upon the
result code passed to it by the login screen.

I have read all the documentation about handlers etc., and couldn't find
a way to do this. I know about notes/pnotes, but aren't they for passing
values from one handler to other. How can my CGI script use them? And if
it is possible for my CGI script to use them, would that be safe when
multiple users are trying to log in?

One more question. I redirect the incoming request by calling
$r-uri($new_uri) in my PerlTransHandler. How can I make the browser
show this new location in its address bar?

Let me know if you need to know more about any aspect of my
implementation. And, thanks for your help.

-vish




Re: cgi-script to handler communication [MP2]

2003-01-16 Thread Stas Bekman
Vishal Verma wrote:

Though it's probably not as fast as adjusting the headers via the api in 
the response handlers. However since you aren't telling what you are 
trying to do I can't give you a better advice.


Here's what I'm trying to do:

I am implementing a login/logout mechanism. The user can't access any
page till he logs in. That is any attempt to access pages without
logging in will be redirected to the login screen. I have successfully
implemented this part. The login page is generated by a CGI script. Once
the user logs in successfully, I want to set a cookie. That's the reason
why I want the login CGI script to pass the result to my handler. The
handler, which must be run after the CGI script has been run, will
decide to modify the output header (to set cookie) depending upon the
result code passed to it by the login screen.


I don't understand why don't you do that in your cgi script (btw, is it 
running under mod_perl/registry or just mod_cgi?). Why do you need yet 
another handler?

I have read all the documentation about handlers etc., and couldn't find
a way to do this. I know about notes/pnotes, but aren't they for passing
values from one handler to other. How can my CGI script use them? And if
it is possible for my CGI script to use them, would that be safe when
multiple users are trying to log in?


If it's a mod_perl registry script, you have an access to the request 
object. Either via my $r = shift; at the beginning of your script or via 
Apache-request (which retrieves the globally stored req object)

If it's a script running under the mod_cgi handler, I don't think you can.

One more question. I redirect the incoming request by calling
$r-uri($new_uri) in my PerlTransHandler. How can I make the browser
show this new location in its address bar?


in mod_cgi scripts:

  print Location: $new_location;

or

  use CGI;
  print CGI-new-redirect($new_location);

or talking mod_perl, see for example:

http://perl.apache.org/docs/1.0/guide/snippets.html#Sending_Cookies_in_REDIRECT_Response

__
Stas BekmanJAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide --- http://perl.apache.org
mailto:[EMAIL PROTECTED] http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com




Re: cgi-script to handler communication [MP2]

2003-01-16 Thread Nick Tonkin

Umm, sanity check: You _have_ checked out the many packages and modules
that do just this under mod_perl, haven't you?

On 16 Jan 2003, Vishal Verma wrote:

  Though it's probably not as fast as adjusting the headers via the api in 
  the response handlers. However since you aren't telling what you are 
  trying to do I can't give you a better advice.
 
 Here's what I'm trying to do:
 
 I am implementing a login/logout mechanism. The user can't access any
 page till he logs in. That is any attempt to access pages without
 logging in will be redirected to the login screen. I have successfully
 implemented this part. The login page is generated by a CGI script. Once
 the user logs in successfully, I want to set a cookie. That's the reason
 why I want the login CGI script to pass the result to my handler. The
 handler, which must be run after the CGI script has been run, will
 decide to modify the output header (to set cookie) depending upon the
 result code passed to it by the login screen.
 
 I have read all the documentation about handlers etc., and couldn't find
 a way to do this. I know about notes/pnotes, but aren't they for passing
 values from one handler to other. How can my CGI script use them? And if
 it is possible for my CGI script to use them, would that be safe when
 multiple users are trying to log in?
 
 One more question. I redirect the incoming request by calling
 $r-uri($new_uri) in my PerlTransHandler. How can I make the browser
 show this new location in its address bar?
 
 Let me know if you need to know more about any aspect of my
 implementation. And, thanks for your help.
 
 -vish
 
 

- nick

   
Nick Tonkin   {|8^)