Reputation: 1010
I am running the below code in two different environments with below mentioned versions and outputs:
Environment 1 (Perl : 5.14.1 , CGI module : 3.52, Apache : 2.4.12) outputs:
Content-Type: text/html; charset=ISO-8859-1 Hello Everybody .. !
Environment 2 (Perl : 5.6.1 , CGI module : 2.752, Apache : 1.1) outputs:
Hello Everybody .. !
I have seen that the CGI header function has undergone some changes in 3.52 from 2.752. Can anybody please help me understand if the difference in output for printing the header twice is due to the CGI version or Apache version ?
use strict;
use warnings;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $q = CGI->new;
print $q->header();
print $q->header();
print $q->start_html();
warn "This is test header issue script \n";
print "Hello Everybody .. !";
print $q->end_html();
Upvotes: 0
Views: 187
Reputation: 385789
Adding the following will suppress duplicate headers in newer versions:
use CGI qw( -unique_headers );
If that causes an error in the older version, you can use the following instead:
{
no warnings qw( once );
$CGI::HEADERS_ONCE = 1;
}
Upvotes: 2