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

I need to able to add an %ENV varible for a cgi script, so it says until the session over. Any thoughts?

Replies are listed 'Best First'.
(Ovid) Re: creating %ENV varibles
by Ovid (Cardinal) on Jun 15, 2001 at 21:33 UTC

    Did you mean 'so it *stays* until the session is over'?

    In any event, any changes you make to %ENV will affect your current process and any child processes that it spawns, but you cannot affect the environment on which you run by setting a value in this hash. Since you mentioned 'session', I assume that you're talking about multiple invocations of a CGI script. Any change you make to %ENV in one invocation will usually not be available to subsequent invocations (unless you're running mod_perl or something like that).

    That being said, what exactly are you trying to accomplish? You will probably have to find another solution. How are you trying to maintain the session and what are you trying to accomplish with a session? In other words, what did you want to set in %ENV and why did you want to do this? We might be able to give you some pointers from there.

    Cheers,
    Ovid

    Join the Perlmonks Setiathome Group or just click on the the link and check out our stats.

      i am trying to write an authenication script on a IIS system. I need to able to set the $ENV{'REMOTE_USER'} varible once i have check there password.

        Under normal circumstances, $ENV{REMOTE_USER} is something that the user's client (browser) may or may not send; any decent one (i.e. one your users will actually use) will re-send the user name on each request after clearing HTTP Basic authentication, as per RFC (i.e. it's a standardized mechanism). I don't know how to implement Basic auth in IIS, but I'm certain it's relatively easy.

        If you can't use Basic Auth, I'd suggest you look into storing session data on the server. This can range from using a flat file to using a database management system (like MySQL or PostgreSQL).

        Of course you'll need some way of identifying a request as belonging to a session, so you'll need to maintain state; the easiest way to do this is (IMO) with cookies (see CGI::Cookie, for example or with some kind of URL-mangling. But look first at using Basic Auth.

        perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'
Re: creating %ENV varibles
by arturo (Vicar) on Jun 15, 2001 at 21:31 UTC

    Sure: $ENV{VARIABLE_NAME} = [value];

    %ENV is a read-write hash.

    perl -e 'print "How sweet does a rose smell? "; chomp ($n = <STDIN>); +$rose = "smells sweet to degree $n"; *other_name = *rose; print "$oth +er_name\n"'