You are viewing a plain text version of this content. The canonical link for it is here.
Posted to embperl@perl.apache.org by Will Schroeder <ws...@schroedernet.net> on 2004/12/09 16:22:13 UTC

session question

I have used embperl with great success in a number of projects but I
have never needed to keep session information until now and I find
myself a little confused.
Here is the dilemma: I can insert session info into mysql but I am not
sure how to go about restoring session data.
I have a form that has two radio buttons 1: Have a login 2: Need a
login. If the user submits "need" a form opens that accepts a username
and a PIN. After submitting that information I move the user through a
few quiz questions save the data and exit. The %udat works great when
the app is used this way. The problem I have is restoring session data
when I open new pages. The $udat{_session_id} prints out the session
number yet I can not get $udat{User}.
I have a feeling that I need the $r - GetSession somehow but when I use
that [- $r -> GetSession -] I get a
"Can't call method "GetSession" on an undefined value" error.
What do I need to do here???
I have attached the main form and inlined some other relevent snippets.
BTW: when I get this to work I will be more that happy to fully document
what I did post it back here.
Apache 1.3.33, embperl 1.3.6, mod_perl 1.2.9, apache::session 1.6,
apache::sessionX 2.00b5
The Trying to restore session page:
[- use Apache::Session::MySQL; -]
[- use Apache; -]
[- use DBI; -]
[- $req = shift; -]
[- $r -> GetSession; -]
<p> [+ $udat{_session_id} +]</p>
<p> [+ $udat{Token} +]</p>
[- $cookie = $udat{_session_id}; -]

[-  my %session; -]
[- tie %session, 'Apache::Session::MySQL', $cookie, {
      DataSource => 'dbi:mysql:sessions', #these arguments are
      UserName   => 'sessions',         #required when using
      Password   => 'sessions',           #MySQL.pm
      LockDataSource => 'dbi:mysql:sessions',
      LockUserName   => 'sessions',
      LockPassword   => 'sessions'
}; -]
####################################################
httpd.conf options
<Directory "/usr/local/apache/htdocs/">
        PerlSetEnv EMBPERL_OBJECT_BASE base.epl
        PerlSetEnv EMBPERL_OBJECT_APPNAME infosec
        PerlSetEnv EMBPERL_ESCMODE 0
        #PerlSetEnv EMBPERL_OPTIONS 262144
        PerlSetEnv EMBPERL_OBJECT_OPTIONS 16
        #PerlSetEnv EMBPERL_DEBUG 2097152
        #PerlSetEnv EMBPERL_LOG "/tmp/embperl.log"
        PerlSetEnv EMBPERL_SESSION_ARGS
"DataSource=dbi:mysql:session;hostname=localhost UserName=sessions
Password=password"
        PerlSetEnv EMBPERL_SESSION_CLASSES "MySQL Semaphore"
        PerlSetEnv EMBPERL_OBJECT_FALLBACK xerror.html



Notice: This e-mail and any attachments are confidential
and may be subject to legal or some other professional
privilege. They are intended solely for the attention and
use of the named addressee(s). They must not be disclosed
to any person without authorisation.

This e-mail and any attachments are also subject to
copyright. They may only be copied or distributed with
the consent of the copyright owner. If you are not
named addressee you must not use, disclose, retain or
reproduce all or any part of the information contained
in this e-mail or any attachments.

Re: session question

Posted by ___cliff rayman___ <cl...@rayman.com>.
Will Schroeder wrote:

>----snip----
>The Trying to restore session page:
>[- use Apache::Session::MySQL; -]
>[- use Apache; -]
>[- use DBI; -]
>[- $req = shift; -]
>[- $r -> GetSession; -]
>
shouldn't this be?
[- $req->GetSession; -]

you are getting the request into $req then trying to use $r which has 
not been defined AFAICS.

-- 
_____cliff_rayman_____cliff_@_rayman_._com_____



---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: session question

Posted by Angus Lees <gu...@inodes.org>.
At Thu, 09 Dec 2004 21:05:24 -0600, Will Schroeder wrote:
> 1: in a pattern match like [$ if ( $fdat{QC} =~ m/(\d+)/  ) $]
> [- $num = $1 -]
> for example. The $1 variable never seems to get populated during the
> match like in a regular old perl script.

aiui, the value of $1, etc variables are "lexically scoped" in perl.

so this should work fine:
[-
  if ( $fdat{QC} =~ m/(\d+)/ ) {
    $num = $1;
  }
-]

whereas your code gets turned into something more like this by
embperl:

 if ( eval { $fdat{QC} =~ m/(\d+)/ } ) {
   eval { $num = $1 };
 }

so $1 loses its value across embperl blocks, in the same way that "my"
variables, etc are also limited to a single embperl block
(ignoring [* *] blocks for the moment).

-- 
 - Gus


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


Re: session question

Posted by Gerald Richter <ri...@ecos.de>.
Am Freitag, 10. Dezember 2004 04:05 schrieb Will Schroeder:
> I did get it to work with this:
> [- $req_rec = shift; -]
> [- my $udat =  HTML::Embperl::Req::SetupSession($req_rec); -]

You don't need these two lines! Just use %udat. Embperl sets it up for you.

> I just forgot that the default cookie expires when the browser closes so
> the session is lost without changing the timeout on the cookie. duh....

Yes, use EMBPERL_COOKIE_EXPIRE in your httpd.conf

> I do have a couple of observations:
> 1: in a pattern match like [$ if ( $fdat{QC} =~ m/(\d+)/  ) $]
> [- $num = $1 -]
> for example. The $1 variable never seems to get populated during the
> match like in a regular old perl script.

%fdat is a normal Perl hash, so there is no reason why this should not work.

> 2: I have noticed that when I set a page variable using %mdat
> performance is terrible. I will run a debug log and see if I see
> anything. Have you or any one else experienced this? Also, what level
> would you reccomend that I log at?

Consitency Embperl locks the entry when you access %mdat, this might cause 
your requests to be serialized and might cause a bad performance. It might be 
better to use something else then %mdat for storing application data.

Gerald


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org


RE: session question

Posted by Will Schroeder <ws...@schroedernet.net>.
I did get it to work with this:
[- $req_rec = shift; -]
[- my $udat =  HTML::Embperl::Req::SetupSession($req_rec); -]
I just forgot that the default cookie expires when the browser closes so
the session is lost without changing the timeout on the cookie. duh....
I do have a couple of observations:
1: in a pattern match like [$ if ( $fdat{QC} =~ m/(\d+)/  ) $]
[- $num = $1 -]
for example. The $1 variable never seems to get populated during the
match like in a regular old perl script.
2: I have noticed that when I set a page variable using %mdat
performance is terrible. I will run a debug log and see if I see
anything. Have you or any one else experienced this? Also, what level
would you reccomend that I log at?
Will Schroeder
On Thu, 2004-12-09 at 20:47 +0100, Gerald Richter wrote:
> > BTW: when I get this to work I will be more that happy to 
> > fully document what I did post it back here.
> > Apache 1.3.33, embperl 1.3.6, mod_perl 1.2.9, apache::session 
> > 1.6, apache::sessionX 2.00b5 The Trying to restore session page:
> > [- use Apache::Session::MySQL; -]
> > [- use Apache; -]
> > [- use DBI; -]
> >....
> 
> 
> You don't need all this stuff in your page, just put some data in %udat and
> you will get it back if the same user hits any other page.
> 
> Embperl handles everything for you. You only need to have Apache::Session
> and Apache::SessionX installed.
> 
> Make sure that make test of Apache::SessionX passes without errors.
> 
> Gerald
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
> For additional commands, e-mail: embperl-help@perl.apache.org

RE: session question

Posted by Gerald Richter <ri...@ecos.de>.
> BTW: when I get this to work I will be more that happy to 
> fully document what I did post it back here.
> Apache 1.3.33, embperl 1.3.6, mod_perl 1.2.9, apache::session 
> 1.6, apache::sessionX 2.00b5 The Trying to restore session page:
> [- use Apache::Session::MySQL; -]
> [- use Apache; -]
> [- use DBI; -]
>....


You don't need all this stuff in your page, just put some data in %udat and
you will get it back if the same user hits any other page.

Embperl handles everything for you. You only need to have Apache::Session
and Apache::SessionX installed.

Make sure that make test of Apache::SessionX passes without errors.

Gerald


---------------------------------------------------------------------
To unsubscribe, e-mail: embperl-unsubscribe@perl.apache.org
For additional commands, e-mail: embperl-help@perl.apache.org