Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

CGI::Session on Windows, can't reread file

by Anonymous Monk
on Jun 28, 2013 at 17:48 UTC ( [id://1041300]=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks. I have script that uses a session file to save a password, and then can reread it on subsequent calls (in a browser, not from command line). This works fine on Linux, but doesn't work on Windows (compiled with Perl2exe, not pp, sorry, bear with me, shouldn't have anything to do with it)

Here is the script:

#!/usr/bin/perl use CGI::Carp qw(fatalsToBrowser); print "Content-type: text/html;charset=UTF-8\n\n"; print "<html><head></head><body>Start test script.<br><br>\n"; use CGI; use CGI::Session; $cgi = new CGI; $sid = $cgi->param('CGISESSID') || undef; print "Incoming sid:$sid<br>"; $SessionFilePath = 'c:\windows\temp'; $session = new CGI::Session("driver:File", $sid, {Directory=>$SessionF +ilePath}) or die CGI::Session->errstr(); $sid = $session->id(); $pwd = "test"; $session->param("pwd", $pwd); $session->save_param($cgi); $session->flush(); print "<br>sid is now $sid.\n"; exit;
The script works to put a session file with the pwd content into \windows\temp. But on a subsequent call, with &CGISESSID=xxxxxxxxxxx added to feed it the session id, it doesn't pay any attention to the session file that it created on the last run, and creates a new one each time instead.

As I said it works on Linux. I'm thinking there is a file permission problem in Windows, but I don't know what it would be or where to start looking. (I do have admin access to the server though)

I'm using \windows\temp because an outside http request didn't have permissions to create files in other places, but it worked to create the file there. That can be setup, but I thought this should work in \windows\temp. Your insights are greatly coveted. Thank-you.

Replies are listed 'Best First'.
Re: CGI::Session on Windows, can't reread file
by poj (Abbot) on Jun 29, 2013 at 12:11 UTC

    Yes, it is permissions, read the end of this node Loading a session from CGI::Session.

    I got it to work by creating a new folder c:/temp/session with read/write/list permissions for user IUSR.

    poj
      Thanks poj - that fixed it! I needed to add IUSR to the security list, with permissions added for read/write/list, etc.
Re: CGI::Session on Windows, can't reread file
by Anonymous Monk on Jun 29, 2013 at 06:20 UTC

    I'm thinking there is a file permission problem in Windows,

    If there was you would get an error

    where to start looking.

    Start with making sure you have the latest CGI/CGI::Session, then employ Basic debugging checklist and Data::Dump the CGI object and the CGI::Session object at strategic points in your program, and try to figure it out :)

      Yeah, you’d think so, but sometimes important errors just get eaten by eval{} structures buried deep-somewhere, and they can be so way-deep that you never do find them.   (Plus, Windows code is often “tested” by Administrators.)   It is annoying, yes, and shouldn’t be that way, yes, but ... when something goes wonkers for “an ordinary user” (i.e. a corporate Joe) in the Windows environment, then permissions, especially to common or temporary files, less-so to the registry keys, have become my first-guess.   (And certainly not “just with Perl.”   Windows has become too-complex for its own good.)   ;-)

Re: CGI::Session on Windows, can't reread file
by Anonymous Monk on Jul 05, 2013 at 12:11 UTC
    OK, maybe I spoke a little too soon. I got it to work in c:\windows\temp by adding the IUSR permission with 'full control'. But I didn't want to leave IUSR with full permissions in Windows\temp, so I tried to change the directory to somewhere else, like c:\session. Didn't work. No matter what I do, I can't seem to change the folder it's going to work in, it always creates the file in c:\windows\temp. How do I get it to go somewhere else? My session creation statement is the same as before, with the folder hardcoded:
    $session = new CGI::Session(undef, $sid, {Directory=>'c:\session'}) or + die CGI::Session->errstr();
    I also don't get any error msg from the die statement.

      Does it die with a non-existent directory like z:\session ?

      poj
        Actually I found the problem, it was a problem with the script not calling back on itself properly. It's working again now. Thanks muchly again.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1041300]
Approved by kcott
Front-paged by Anneq
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2024-04-19 14:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found