Getting PassEnv to work, or retrieving custom HTTP Headers

Discussion in 'Apache' started by theRatWonder, Apr 15, 2007.

  1. #1
    Basically, could you tell me how to set a new environment variable from an HTTP request header, or look below and tell me if I'm using "PassEnv" wrongly.

    Details:
    -------

    The problem is, I want to set a variable with a perl script, redirect the page elsewhere and have the variable be able to be picked up at the other end.

    Obviously environment variables are only for that sessions so setting an environment variable doesn't work.

    You would think that the apache "PassEnv" command would be specifically for this, but I tried this and it doesn't work after I set an environment variable in perl (those not fluent in perl just take my word for it, this should work and doesn't):

    start.cgi:
    #!/usr/bin/perl
    use CGI;
    $ENV{'myvar'} = 'hello world!';
    print CGI->redirect('end.cgi');
    exit;
    Code (markup):
    .htaccess:
    PassEnv myvar
    Code (markup):
    end.cgi:
    #!/usr/bin/perl
    use CGI;
    print CGI->header();
    if($ENV{'myvar'}) {print "success!";}
    else {print "failure :(";}
    exit;
    Code (markup):
    Running start.cgi in a browser produces "failure :(".

    So the other idea I had was to send it in the header, and then retrieve it from the header at the other end:

    start.cgi:
    #!/usr/bin/perl
    use CGI;
    print CGI->redirect(
    -uri=>'end.cgi',
    -myvar=>'hello world!'
    );
    exit;
    Code (markup):
    .htaccess:
    # I was hoping I could somehow use 
    # SetEnv to set the variable from the http header
    SetEnv myvar #*$!xx
    Code (markup):
    end.cgi would be the same.

    Please let me know if you can help.
    Thanks.
    Robin.

    P.s.
    By the way I can prove (and have tested) that the environment variable setting and retrieving in my scripts above is correct as follows:

    start.cgi:
    #!/usr/bin/perl
    use CGI;
    $ENV{'myvar'} = 'hello world!';
    print CGI->header();
    print `perl end.cgi`;
    exit;
    Code (markup):
    end.cgi:
    #!/usr/bin/perl
    if($ENV{'myvar'}) {print "success!<br />" . $ENV{'myvar'};}
    else {print "failure :(";}
    exit;
    Code (markup):
    Running start.cgi in a browser prints out:
    Success!
    hello world!
     
    theRatWonder, Apr 15, 2007 IP