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

I have web site that when uses javascript and cgi. But when i user javascript to open a cgi script that is written in perl, none of the $ENV varibles get created, i any way to force the the varibles to be created or is there a work around?

Replies are listed 'Best First'.
Re: %ENV and Javascript
by chromatic (Archbishop) on Apr 03, 2000 at 07:34 UTC
    Hash keys are case sensitive. $ENV{HTTP_referer} is not the same as $ENV{HTTP_REFERER} (unless you do some object-oriented or tied magic). Try capitalizing 'referer'.

    Otherwise... are you using JavaScript to redirect the user to the script, or is it a client-side include sort of thing? This may be an example for XYZ Questions.

Re: %ENV and Javascript
by little_mistress (Monk) on Apr 03, 2000 at 09:05 UTC
    Im not so sure that this is an appropriate question. Forgive me if im speaking out of line, but CGI, though commonly done with perl, can be done in any language, with any webserver. that would be the domain of the question. As to why the %ENV hash isnt being created, you may want to look at your documentation for you webserver. As far as I know the %ENV hash is created each and every time a CGI request comes into a perl script. Just like there are environmental variables for bash, chs, sh, corba, and python scripts.

    It seems like your question has to do with CGI and various network software not perl

Re: %ENV and Javascript
by btrott (Parson) on Apr 03, 2000 at 05:38 UTC
    Which environment variables are you talking about? It's possible that, for some env. variables, like HTTP_REFERER, they're not getting set because you're invoking the new window in a different way than, say, when a user clicks on a link. Browsers often only send the HTTP_REFERER variable, for example, when you've actually clicked on a link.

    So, I guess the question would be: are *none* of the env. variables getting set--which would be a bit odd and would indicate some trouble, possibly--or just the specific ones that you're using?

    for my $key ($keys %ENV) { print $key, ": ", $ENV{$key}, "<br>\n"; }
    In case you haven't tried seeing which ones are being set already.
RE: %ENV and Javascript
by Anonymous Monk on Apr 04, 2000 at 01:20 UTC
    Why not make a subroutine to print out the %ENV hash so you can see what is really in it? Something like:
    print_env { foreach $key (keys(%ENV)) { print $key, " = ", $ENV{$key}, "\n"; } }
Re: %ENV and Javascript
by outcast (Monk) on Apr 03, 2000 at 06:43 UTC
    i have listed all the i have done that but none I mean none of the $env are there when i open the page with javascript.
Re: %ENV and Javascript
by btrott (Parson) on Apr 03, 2000 at 06:47 UTC
    Could you try posting a bit of your code? And what exactly do you mean when you say that you "use javascript to open a cgi script"? What javascript command are you using?
Re: %ENV and Javascript
by outcast (Monk) on Apr 03, 2000 at 07:09 UTC
    if ($ENV{"HTTP_referer"} eq "http://www.mysite.com/blah.html") { &main; exit; ) else ( print "You don't belong here"; ) i am using a spanning menu,which was written in javascript, that friend of my used on his site. when i use the menu to open on of my script the $ENV{"HTTP_REFERER"} does not get created and the if statement returns false.
Re: %ENV and Javascript
by outcast (Monk) on Apr 03, 2000 at 07:43 UTC
    i am sorry REFERER is capitalized. my bad. with the java script, it is a menu with animation if you click on a catageory is drops down a sub menu and you click on one of the choice and it takes you to the the script, but that is handle on client side.
Re: %ENV and Javascript
by outcast (Monk) on Apr 03, 2000 at 07:13 UTC
    yes those () instead of {} are typeos