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

Hi Perl monks. I have a quandry about ActivePerl on Windows NT, and CGI::Session. I have a script that is supposed to do a simple task: create a session file in a folder on NT and store a value in it. Then I can retrieve the value later in a second call to the script. This is intended to be done in an internet browser, but for now I'm just using the NT command prompt to debug. Here's the script:

#!/usr/bin/perl use CGI; use CGI::Session; use CGI::Carp qw(fatalsToBrowser); $cgi = new CGI; $sid = $cgi->param('CGISESSID') || undef; $destdir = 'd:\web\libsearch'; $session = new CGI::Session("driver:File", $sid, {Directory=>$destdir} +) or die CGI::Session->errstr(); $sid = $session->id(); print "<br>sid=$sid, $destdir\n"; #store the variable $testvalue = "abc"; $session->param("testvar", $testvalue); $session->save_param($cgi); #retrieve the variable $retrieved = $session->param("testvalue"); print "<br>retrieved:$retrieved \n"; exit;
As it is, no file is created in the 'd:/web/libsearch' folder. If I use
$destdir = File::Spec->tmpdir;
instead of a hardcoded folder, I get the logged-in temp folder for administrator (which is how I am logged in), and the file is created & all is good. The hardcoded folder has 'everybody' listed for permissions, so it shouldn't be a permissions issue.

If I compile it into an exe (with Perl2Exe - any comments on that?) and run it from a webbrowser like I intend to do eventually here, it uses c:\winnt\temp as the temp folder value, and still no file gets created. (also no file with the hardcoded value).

Why is it unable to create a file in some circumstances? My permissions don't seem to be a problem, so what is happening in CGI::Session that it doesn't like the other folder? Thanks in advance! Michael

Replies are listed 'Best First'.
Re: CGI Session - not creating session file
by Joost (Canon) on Aug 02, 2007 at 20:11 UTC
    Do you get a server error? Is there anything of interest in the webserver's log?

    If so, it's likely the webserver doesn't have permission to write to that directory.

    Also note that using \ backslashes in paths is usually not needed even on windows since / forward slashes work as well and have less issues (for instance; "c:\some\newthing" contains a newline, while "c:/some/newthing" does not)

    As an aside, what do you want to accomplish with using perl2exe? There's no real benefit to using it, besides easier distribution to sites that don't have perl installed - and I'm guessing you already have some sort of control over the server you're running this program on.

      I haven't looked in the servers log, I should do that. I do have full access to this server, but the script will be run on other servers yet that I don't have access to.

      I tried the backslashes, and as was mentioned, they work fine either way. I did find some issues with using the forward slashes, but those errors come up right away and are easy enough to steer around.

      Why wouldn't the webserver have permission to write to the system's temp folder? I don't believe this server was set up with any special considerations like that. Also, the folder that the script is in is the d: folder I mentioned, it has 'everybody' permissions on it - what more could a webserver ask for? I want to ask about your comment on perl2exe - how do I make the computer run perl script without having it compiled? I guess I haven't tried the most obvious way - just call it from the URL line - maybe I'll have to associate the extension with NT's Perl & it'll just 'go'. Would it take something else?

      Michael

Re: CGI Session - not creating session file
by oxone (Friar) on Aug 02, 2007 at 20:04 UTC
    Couple of things to check:

    Can you do a straight open to create a file in your $destdir?

    Have you tried defining $destdir using forward slashes rather than backslashes, which sometimes helps.

Re: CGI Session - not creating session file
by whereiskurt (Friar) on Aug 02, 2007 at 20:07 UTC

    Just a quick thought -- try changing:

    $destdir = 'd:\web\libsearch';

    To:

    $destdir = 'd:/web/libsearch';

    Not sure, but I'm guessing that File::Spec->tmpdir is returning a path with the forward slashes (/).

    Kurt