[cgiapp] CGI::Session example:

2002-05-16 Thread Sherzod B. Ruzmetov


I have just finished the CGI::Session demo script:

http://modules.ultracgis.com/cgi-bin/session

Enjoy!

Sherzod


-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




[cgiapp] Re: one last question about CGI::Application and CGI::Session

2002-05-16 Thread Sherzod B. Ruzmetov

> How do I access the $session object from other subs?

When I use it in my sites, I just pass object as an argument 
to other subs ( I don't use CGI::Application)

print default($cgi, $session);

But since you are using CGI::Application, it provides
handy param() method. So when you create the session object once, 
you just assign it to CGI::Application's parameter:

$session = new CGI::Session::File(...) or die 
$CGI::Session::errstr;
$self->param("session-obj", $session);

Note that $self is reference to CGI::Application available from inside 
your cgiapp_init() method. Then in your other subs you will do:

sub foo_bar {
my $self = shift;
my $session = $self->param("session-obj");

}

DO NOT confuse CGI::Application's param() method with CGI::Session's 
param() 
method. 

Good luck

P.S. I am working on a CGI::Session  demo right now, and should be 
available sometime
tonight. 




-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




[cgiapp] one last question about CGI::Application and CGI::Session

2002-05-16 Thread Zachary Buckholz

How do I access the $session object from other subs?

In the CGI::Session docs it shows the following example


# now, if the user submitted his first name in a form, we can save it
# in our session
my $first_name  = $cgi->param("first_name");
$session->param("first_name", $first_name);


The above is assuming that this is done within the same sub that the
$session object was created.

So when I am using CGI::Application and I am working in a run_mode sub how
can I best access the session object and update a key.

Simple example would be a counter

You have accessed this page 9 times.

Zack

-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: [cgiapp] CGI::App and CGI::Session

2002-05-16 Thread Sherzod B. Ruzmetov


> use constant COOKIE => "saint";
>
> But I should propably be using .securitysaint.com 

No, COOKIE constant was just a name of the cookie to be sent.
It has nothing to do with the domain name.

Alternative for using constant is to give the name 
for the cookie on the fly:

$new_cookie = $q->cookie(-name=>"SESSION_ID", 
-value=>$session->id());

So the name of the cookie can be anything. 
For other options availabel for CGI::cookie() method
refere to CGI.pm online documentation.

I guess I should include some demo scripts to the
CGI-Session distribution. 


ttyl

Sherzod



-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: [cgiapp] CGI::App and CGI::Session

2002-05-16 Thread Zachary Buckholz

Thanks for your feedback, I am using the cookie constant as follows

package Saint::WebApp;
use base 'CGI::Application';
use strict;
use CGI::Session::File;

use constant COOKIE => "saint";

But I should propably be using .securitysaint.com 


- Original Message - 
From: "Sherzod B. Ruzmetov" <[EMAIL PROTECTED]>
To: "Zachary Buckholz" <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, May 16, 2002 3:10 PM
Subject: Re: [cgiapp] CGI::App and CGI::Session


> >
> >my $new_cookie = $self->header_props(-name=>COOKIE,
> -value=>$session->id);
> >  $self->header_props(-cookie=>$new_cookie);
> > }
> 
> $new_cookie is not returned from the header(), it is returned from the
> CGI.pm's
> cookie() method. First you create PROPER HTTP cookie, then pass it to
> header_props():
> 
> $new_cookie = $q->cookie(-name=>COOKIE, -value=>$session->id);
> $self->header_props(-cookie=>$new_cookie);
> 
> But let's ask Jesse for more insights on this, since I'm not quite
> familiar with CGI::Application.
> 
> Another thing, you are using COOKIE constant from the CGI::Session
> manual, and I assume you have a line something like:
> 
> use constant COOKIE => 'MY_SITE_SID';
> 
> at the top of your program, do you? If you were using 'strict' pragma
> it would let you know.
> 
> 
> ttyl
> 
> Sherzod
> 
> 
> 
> 
> -
> Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 

-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: [cgiapp] CGI::App and CGI::Session

2002-05-16 Thread Sherzod B. Ruzmetov

>   
>my $new_cookie = $self->header_props(-name=>COOKIE, 
-value=>$session->id);
>  $self->header_props(-cookie=>$new_cookie);
> }

$new_cookie is not returned from the header(), it is returned from the 
CGI.pm's
cookie() method. First you create PROPER HTTP cookie, then pass it to 
header_props():

$new_cookie = $q->cookie(-name=>COOKIE, -value=>$session->id);
$self->header_props(-cookie=>$new_cookie);

But let's ask Jesse for more insights on this, since I'm not quite
familiar with CGI::Application.

Another thing, you are using COOKIE constant from the CGI::Session
manual, and I assume you have a line something like:

use constant COOKIE => 'MY_SITE_SID';

at the top of your program, do you? If you were using 'strict' pragma
it would let you know.


ttyl

Sherzod




-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: [cgiapp] CGI::App and CGI::Session

2002-05-16 Thread Zachary Buckholz

Sorry to be a little slow about this, the code below does appear to working
now. But I am concerned that it might not be the correct way of doing it.

I seem to have a little disfunctional code at the end; last two lines. Is
that right?


sub cgiapp_init {
my $self = shift;
my $q = $self->query();
my $c_sid = $q->cookie(COOKIE) || $q->param("c_sid") || undef;
my $session = new CGI::Session::File($c_sid,
{
LockDirectory   => '/tmp/locks',
Directory   => '/tmp/sessions'
});
my $new_cookie =
$self->header_props(-name=>COOKIE, -value=>$session->id);
$self->header_props(-cookie=>$new_cookie);
}

-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




Re: [cgiapp] CGI::App and CGI::Session

2002-05-16 Thread Sherzod B. Ruzmetov

Hi

> But do I set the
> $self->header_props inside the cgiapp_init sub then do nothing else. Or
> should I follow the CGI::Session docs and initialize a new instance of
> CGI.pm and print the header directly from the cgiapp_init sub?

If you are using CGI::Application, then you don't have to create
new instance of CGI.pm, because CGI::Application's query() method
retruns it for you. I don't quite use CGI::Application, but as 
Jesse once explained, you don't need to use header(), but use
header_props() instead.

CGI::Session's documentation makes use of CGI.pm for 
making working with cookies and queries easier. So you don't
have to use CGI.pm if you don't want to, it still does
it's job without it (except load_param() and save_param() methods)

For complete documentation of CGI::Session refer to
http://modules.ultracgis.com/CGI/Session.html, 
http://modules.ultracgis.com/CGI/Session/File.html.

Other drivers include, 
http://modules.ultracgis.com/CGI/Session/DB_File.html and
http://modules.ultracgis.com/CGI/Session/MySQL.html.

Note: If your CGI::Session is older then 2.1, please upgrade is ASAP.

--  
Sherzod






-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




[cgiapp] CGI::App and CGI::Session

2002-05-16 Thread Zachary Buckholz

What is the best way to combine CGI::Session  and CGI::Application

It was recommended that I use the cgiapp_init, which I am attempting to do.
But do I set the
$self->header_props inside the cgiapp_init sub then do nothing else. Or
should I follow the CGI::Session docs and initialize a new instance of
CGI.pm and print the header directly from the cgiapp_init sub?

Doing it as listed below does set the cookie and creates a session , but the
header is sent and mixed with the output from the rest of the module. Thus
giving me:

Content-Type: text/html; charset=ISO-8859-1


  Test Template
  
  My Home Directory is
  
  My Path is set to
/usr/local/sbin:/usr/sbin:/sbin:/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin
:/usr/local/sbin:/usr/bin/X11:/usr/X11R6/bin:/root/bin
  



sub cgiapp_init {
my $self = shift;
# Optional Pre-Setup Initalization code

use CGI;

my $cgi = new CGI;

my $c_sid = $cgi->cookie(COOKIE) || undef;

my $session = new CGI::Session::File($c_sid,
{
LockDirectory   => '/tmp/locks',
Directory   => '/tmp/sessions'
});

my $new_cookie = $cgi->cookie(-name=>COOKIE, -value=>$session->id);

print $cgi->header(-cookie=>$new_cookie);

}


Any examples would be appreciated, and any links to online examples would
also be helpful. Searching deja for these two modules did not return any
posts I could learn from.


Thanks
zack

-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: [cgiapp] HTML::Template Question and where is list archive?

2002-05-16 Thread Roy Rubin


> 
> I am just starting out using CGI::Application and would like to 
> see an example of how to call HTML::Template and pass it param's?
> 
> I was also looking for a cgiapp list archive that I could search 
> to see if anyone else may have posted this and gotten a response. 
> Is there a web based archive?
> 
> The following code gives me 
> 
> HTML::Template=HASH(0x822f464)
> 
> When I access www.securitysaint.com/cgi-bin/saint.cgi
> 
> 
> sub show_main {
> my $self = shift;
> 
> # Get CGI query object
> my $q = $self->query();
> 
> my $tmpl_obj = $self->load_tmpl('main.tmpl');
> 
> my $output = '';
> 
> $tmpl_obj->param(HOME => $ENV{HOME});
> $tmpl_obj->param(PATH => $ENV{PATH});
> 
> $output .= $tmpl_obj;
> return $output;
> 
> }
> 
> Any pointer in the right direction would be helpful.
> 
> Thanks
> zack



It should be $output .= $tmpl_obj->output;


Roy
Irubin Consulting
http://www.irubin.com

-
Web Archive:  http://www.mail-archive.com/cgiapp@lists.vm.com/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




[cgiapp] HTML::Template Question and where is list archive?

2002-05-16 Thread Zachary Buckholz

I am just starting out using CGI::Application and would like to see an example of how 
to call HTML::Template and pass it param's?

I was also looking for a cgiapp list archive that I could search to see if anyone else 
may have posted this and gotten a response. Is there a web based archive?

The following code gives me 

HTML::Template=HASH(0x822f464)

When I access www.securitysaint.com/cgi-bin/saint.cgi


sub show_main {
my $self = shift;

# Get CGI query object
my $q = $self->query();

my $tmpl_obj = $self->load_tmpl('main.tmpl');

my $output = '';

$tmpl_obj->param(HOME => $ENV{HOME});
$tmpl_obj->param(PATH => $ENV{PATH});

$output .= $tmpl_obj;
return $output;

}

Any pointer in the right direction would be helpful.

Thanks
zack