Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: having problems w/CGI-Session

by MrCromeDome (Deacon)
on May 20, 2005 at 21:06 UTC ( #459133=note: print w/replies, xml ) Need Help??


in reply to having problems w/CGI-Session

I'm torn between downvoting you for a poorly-asked question and running away screaming, but as tcf03 already chastized you I'll refrain from further. Your question seems to contradict itself, so I'll try to answer your question as best as I understand it.

When you say "Seems a new session file is created w/Netscape but not w/Apache", do you mean that every time a browser makes a request a new session file is created? That's the only thing I can guess that makes sense. If that's the case, you're likely not re-initializing an existing session.

Take a look at the following:
my $session = new CGI::Session(undef, $request, { Directory => "/tmp" +});
This creates a new session object in your code. The first argument declares some things about your session, namely where it is stored and how it is stored. Declaring it as undef will invoke its default behavior, which is ok in this case.. The second argument, $request, is the likely key to this mystery. $request is a CGI object that was declared elsewhere in my code. CGI::Session is going to try to get the existing session ID out of that CGI request object. It may have been passed in the query string, or it might have been passed in the cookie, or as a hidden form field. If CGI::Session can't find that session ID, it will automatically create a new session. The last argument is used for passing configuration arguments to CGI::Session. In this case, we're telling it what directory to put the session files into.

I'm guessing your code may look more like this:
my $session = new CGI::Session(undef, undef, { Directory => "/tmp" });
but as I can't see your code I am wildly speculating. The second undef in this case is always creating a new session.

One other thing I can think of is this:
my $session = new CGI::Session(undef, $sid, { Directory => "/tmp" });
Where $sid is the id of the session you wish to recreate. If you're using this form, then whatever you are using to populate $sid is failing. Chances are you'd be better off with my initial option.

Keep in mind that this is untested as I don't have an iPlanet server to beat on. And I don't know why it behaves differently on the two.

Yes, it's Friday, and I'm grumpy and I want to go home.

Good luck,
MrCromeDome

Replies are listed 'Best First'.
Re^2: having problems w/CGI-Session
by ww (Archbishop) on May 21, 2005 at 02:12 UTC
    I may have misread your intent (in which case, ignore or --), but your question, "do you mean that every time a browser makes a request a new session file is created?" makes me wonder if you're thinking of NS only in terms of the browser.

    googling for netscape+server+iplanet: Configuring Netscape Enterprise or iPlanet web server in Windows... is but one of many hits.

      No confusion :) Please allow me to explain:

      When I first wrote programs that used CGI::Session, I made the same mistake that I describe. . . I accidentally created a new session every time my program ran. Or, to look at it another way, every time the browser made a request of my script on the webserver, a new session was created. Once I realized what I had done, it was an easy thing to fix.

      What I do struggle to understand is why his script appeared to work on Apache but not on iServer. As I never intend on using iServer I don't care all that much either ;) Whether or not it's some sort of bad coincidence or conclusion, or whether its a program bug or configuration issue is impossible to tell unless we get some code though ;) (and at this point I'm doubting that will ever surface).

      Happy weekend!
      MrCromeDome
        "(and at this point I'm doubting that will ever surface)."

        Oh, ye of little faith. :-P

        Here's the code for the 'initialize_session' method that's called from the 'cgiapp_init' method of the 'Base.pm' module that's inherited from 'CGI::Application':

        sub initialize_session
        {
        my $self = shift;
        my $q = $self->query();


        my $session = CGI::Session->new('driver:File',
        $q->cookie('CGISESSID') || $q->param('CGISESSID') || undef,
        { Directory=>'/ctrlacc/lhdsurv/session/mid_yr_rpt_survey' } )
        or die($CGI::Session::errstr);


        # 05-17-2005: See if following code works
        # expire the session itself after 1 idle hour
        $session->expire('+1h');


        #Initialize the session and get the id.
        my $sessionid = $session->id();
        $self->param('sessionid'=>$sessionid);
        $self->param('session'=>$session);


        if ( (! defined($q->cookie('CGISESSID'))) or
        ($sessionid ne $q->cookie('CGISESSID')) )
        {
        # If the session has expired, reset the cookie
        $self->header_add(-cookie => $q->cookie(-name => 'CGISESSID', value => $sessionid, -path=>'/') );
        }
        }
      The server has Apache Web server and Netscape iPlanet installed and apparently each Web server's cgi-bin directory is mapped to the same subdirectory. So in order to run a perl CGI script under each Web server, you need to use a (slightly) different URL.

      The code is writing session data as files in a certain subdirectory on the server. When using the URL for Apache Web server, you get only 1 session file created for you and this file increases in size (i.e., the report data is appended to your existing session file) when you run a report which allows you to display the details of a specific record listed on the report. But when using the URL for Netscape iPlanet, you get a new session file created when you run the report and again when you try to display the details of a specific record.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://459133]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2021-04-20 23:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?