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

I have set up some data in the HTTP headers for my http files and everything works well, but my solution (using .htaccess) does not seem to work for my perl and cgi files. How do I add
CP="NOI ADM DEV PSAi COM ..." policyref="/w3c/php.xml"
to the response header. This sounds like such a simple question, but I can not get it for some reason. Thanks.

Replies are listed 'Best First'.
Re: Using perl to set headers
by dmitri (Priest) on Sep 10, 2003 at 23:29 UTC
    Some questions about your question:
    1. What are 'http files'?
    2. Perl and CGI files? You mean, CGI files written in Perl?
    3. What is your environment? Apache with vanilla CGI, or are you using mod_perl, SpeedyCGI, or something else?
    4. Give a small example of you CGI script printing out headers.

    It will be much easier to answer your question if you provide more info. Thanks.

      Thanks,
      I have a site that consists of mostly static pages with some dynamic scripts (cgi files written in perl). I Put the code I mentioned in an .htacces file (intending appache to add the header to all files). It adds the header to html files (so cookies are set and read properly with html with IE V6.0), but it is not adding it to my dynamic files. I have a
      print "Content-type: text/html\n\n"
      statement at the top of my script and I tried just adding the print
      CP="NOI ADM DEV PSAi COM ..." policyref="/w3c/php.xml";
      but that did not work. I am using vanilla CGI. I am just trying to add the privacy policy to the pages created by my script. Without the policy, there are no other special pieces to the header. I hope that was more helpful. Thanks
        I have a print "Content-type: text/html\n\n" statement at the top of my script and I tried just adding the print CP="NOI ADM DEV PSAi COM ..." policyref="/w3c/php.xml";

        No, it wouldn't. You've already printed a blank line, so according to the HTTP spec, the headers are over. You need to insert your headers before the blank line that ends the headers.

        print "Content-type: text/html CP=\"NOI ADM DEV PSAi COM ...\" policyref=\"/w3c/php.xml\" \n";

        Also, I'm not sure about that formatting on those two headers. Shouldn't HTTP headers have colons followed by spaces instead of equal signs? I'm not familiar with the CP and policyref headers, but I was thinking all headers were formatted the same way, like in most internet protocols. If so, it should be more like this...

        print "Content-type: text/html CP: NOI ADM DEV PSAi COM ... policyref: /w3c/php.xml \n";

        $;=sub{$/};@;=map{my($a,$b)=($_,$;);$;=sub{$a.$b->()}} split//,".rekcah lreP rehtona tsuJ";$\=$ ;->();print$/
Re: Using perl to set headers
by tachyon (Chancellor) on Sep 11, 2003 at 11:14 UTC

    It should look like this:

    Status: 200 OK P3P: policyref="/w3c/p3p.xml", CP="CAO DSP LAW CURa BLAH.." Content-Type: text/html

    You need two \n after the Content-Type as this signifies the end of the header section. Typically you don't bother with the Status line as the server will add it for you.

    The latest versions of CGI.pm and CGI::Simple support P3P in their header/redirect methods. You use them like this:

    use CGI::Simple; my $q = new CGI::Simple; print $q->header( -type=>'text/html',-P3P => 'CAO DSP LAW CURa ADMa DE +Va CUSi BLAH...' ); __DATA__ P3P: policyref="/w3c/p3p.xml", CP="CAO DSP LAW CURa ADMa DEVa CUSi BLA +H..." Content-Type: text/html; charset=ISO-8859-1

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print