Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > how to remove duplicate header line in CGI

Reply
Thread Tools

how to remove duplicate header line in CGI

 
 
dmedhora@gmail.com
Guest
Posts: n/a
 
      09-17-2007
Hi,
When I write a CGI script in perl I seem to get this line printed out
TWICE !

Content-Type: text/html; charset=iso-8859-1

It also shows up in the web browser as the first line, when I execute
the same from my cgi-bin
dir.

Any idea how I may get rid of this duplication ? It could be causing
problems while
I debug and run my programs..

Thanks

 
Reply With Quote
 
 
 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      09-17-2007
http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> Hi,
> When I write a CGI script in perl I seem to get this line printed out
> TWICE !
>
> Content-Type: text/html; charset=iso-8859-1
>
> It also shows up in the web browser as the first line, when I execute
> the same from my cgi-bin
> dir.
>
> Any idea how I may get rid of this duplication ?


Figure out which part of your code is printing both of these, and take out
whichever part it makes the most sense to take out.

You could try to tie STDOUT to something that will filter out
a second header, but at that point you pretty much have to face
the fact that the code is now in control of you and not the other
way around. Time to start working on a fundamental re-design.

If you use fatalsToBrowser then a fatal error might cause an extra header
to be printed if one has already been printed. This has never caused
me a problem, so I just live with it. It tries to guess if you have
already printed a header, but I believe the way it does this, and
the effectiveness of it, changes from version to version.

Xho

--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
 
Reply With Quote
 
 
 
 
Tad McClellan
Guest
Posts: n/a
 
      09-18-2007
(E-Mail Removed) <(E-Mail Removed)> wrote:

> When I write a CGI script in perl I seem to get this line printed out
> TWICE !
>
> Content-Type: text/html; charset=iso-8859-1


> Any idea how I may get rid of this duplication ?



Yes. Find the 2 places in your code that are outputting that header,
and remove one of them.


--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
 
Reply With Quote
 
Ben Bullock
Guest
Posts: n/a
 
      09-18-2007
On Mon, 17 Sep 2007 13:25:11 -0700, dmedhora wrote:

> Hi,
> When I write a CGI script in perl I seem to get this line printed out
> TWICE !
>
> Content-Type: text/html; charset=iso-8859-1


If I try this:

#!/usr/bin/perl
use warnings;use strict;
use CGI;
my $nice_cgi=CGI::new();
print $nice_cgi->header();

I just get it once.

> It also shows up in the web browser as the first line, when I execute
> the same from my cgi-bin
> dir.
>
> Any idea how I may get rid of this duplication ?


It's really, really hard to say why the duplication is occurring without
looking at your script. Perhaps you have something like this, for example:

print $nice_cgi->header();
print $nice_cgi->header();

That would cause the problem you describe. Alternatively,

for (my $i=0; $i < 2; $i++) {
print $nice_cgi->header();
}

would also suffice to create this computational conundrum.

> It could be causing
> problems while
> I debug and run my programs..

 
Reply With Quote
 
dmedhora@gmail.com
Guest
Posts: n/a
 
      09-18-2007
On Sep 17, 9:25 pm, (E-Mail Removed) wrote:
> Hi,
> When I write a CGI script in perl I seem to get this line printed out
> TWICE !
>
> Content-Type: text/html; charset=iso-8859-1
>
> It also shows up in the web browser as the first line, when I execute
> the same from my cgi-bin
> dir.
>
> Any idea how I may get rid of this duplication ? It could be causing
> problems while
> I debug and run my programs..
>
> Thanks


Hi and Thanks for your posts, Well, to add more details to this
It happens only when I use CGI::FormBuilder
So, if I use CGI.pm there is no duplication but if I use
CGI::FormBuilder then I get that duplicate.
Here is some code
================================================== ========
#!/usr/bin/perl

use CGI::FormBuilder;

my @fields = qw(category task status notes);

my $form = CGI::FormBuilder->new(
method => 'post',
fields => \@fields,
validate => {
status => 'INT', # validate
},
required => 'ALL',
);

if ($form->submitted)
{
print $form->confirm(header => 1);
} else {
print $form->render(header => 1);
}
================================================== =======

Note, since I got this problem I've dumped FormBuilder and
settled for plain CGI.pm instead.

 
Reply With Quote
 
Ben Bullock
Guest
Posts: n/a
 
      09-18-2007
On Tue, 18 Sep 2007 06:24:37 -0700, dmedhora wrote:

> Hi and Thanks for your posts, Well, to add more details to this
> It happens only when I use CGI::FormBuilder
> So, if I use CGI.pm there is no duplication but if I use
> CGI::FormBuilder then I get that duplicate.


I ran the script you supplied, but I only got the offending message once.
 
Reply With Quote
 
Mumia W.
Guest
Posts: n/a
 
      09-18-2007
On 09/18/2007 08:40 AM, Ben Bullock wrote:
> On Tue, 18 Sep 2007 06:24:37 -0700, dmedhora wrote:
>
>> Hi and Thanks for your posts, Well, to add more details to this
>> It happens only when I use CGI::FormBuilder
>> So, if I use CGI.pm there is no duplication but if I use
>> CGI::FormBuilder then I get that duplicate.

>
> I ran the script you supplied, but I only got the offending message once.


Same here.

 
Reply With Quote
 
dmedhora@gmail.com
Guest
Posts: n/a
 
      09-19-2007
On Sep 18, 4:41 pm, "Mumia W." <paduille.4061.mumia.w
(E-Mail Removed)> wrote:
> On 09/18/2007 08:40 AM, Ben Bullock wrote:
>
> > On Tue, 18 Sep 2007 06:24:37 -0700, dmedhora wrote:

>
> >> Hi and Thanks for your posts, Well, to add more details to this
> >> It happens only when I use CGI::FormBuilder
> >> So, if I use CGI.pm there is no duplication but if I use
> >> CGI::FormBuilder then I get that duplicate.

>
> > I ran the script you supplied, but I only got the offending message once.

>
> Same here.


Hi,
Well when I run the script on the command line I get two headers i.e
"Content Type" lines
printed out, is that good or bad ?
I have a cat and head display below:
[root@localhost cgi-bin]# cat h.pl
#!/usr/bin/perl
use CGI::FormBuilder;

my @fields = qw(category task status notes);

my $form = CGI::FormBuilder->new(
method => 'post',
fields => \@fields,
validate => {
status => 'INT', # validate
},
required => 'ALL',
);

if ($form->submitted)
{
print $form->confirm(header => 1);
} else {
print $form->render(header => 1);
}
[root@localhost cgi-bin]# ./h.pl | head
Content-Type: text/html; charset=iso-8859-1

Content-Type: text/html; charset=iso-8859-1

<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en_US"
xml:lang="en_US">

[root@localhost cgi-bin]#

 
Reply With Quote
 
Ben Bullock
Guest
Posts: n/a
 
      09-19-2007
On Wed, 19 Sep 2007 06:46:05 -0700, dmedhora wrote:


> Well when I run the script on the command line I get two headers i.e
> "Content Type" lines
> printed out, is that good or bad ?


That's bad.

> I have a cat and head display below:


> [root@localhost cgi-bin]# ./h.pl | head
> Content-Type: text/html; charset=iso-8859-1
>
> Content-Type: text/html; charset=iso-8859-1


It might be a bug in your version of CGI::FormBuilder. I'm using the
latest version, including dependencies. One suggestion which might fix
this is you could try using "cpan upgrade" to make sure that you're up to
date with all the modules you're using. Also it might be a good idea to
try running the same script on a different machine.
 
Reply With Quote
 
Mumia W.
Guest
Posts: n/a
 
      09-19-2007
On 09/19/2007 08:46 AM, (E-Mail Removed) wrote:
>
> Hi,
> Well when I run the script on the command line I get two headers i.e
> "Content Type" lines
> printed out, is that good or bad ? [...]


As Mr. Morrow said, that's bad.

When I run the following script on the command line, I get only one
Content-Type header:

----------------------script------------------
#!/usr/bin/perl

use CGI::FormBuilder;
use Module::Versions::Report;

my @fields = qw(category task status notes);

my $form = CGI::FormBuilder->new(
method => 'post',
fields => \@fields,
validate => {
status => 'INT', # validate
},
required => 'ALL',
);

if ($form->submitted)
{
print $form->confirm(header => 1);
} else {
print $form->render(header => 1);
}
----------------------end---------------------

Here is the output:

Content-Type: text/html; charset=ISO-8859-1

<html><head><title>Form Build</title>
<script language="JavaScript1.3"><!-- hide from old browsers
function validate (form) {
var alertstr = '';
var invalid = 0;

// standard text, hidden, password, or textarea box
var category = form.elements['category'].value;
if ( ((! category && category != 0) || category === "")) {
alertstr += '- You must enter a valid value for the "Category"
field\n';
invalid++;
}
// standard text, hidden, password, or textarea box
var task = form.elements['task'].value;
if ( ((! task && task != 0) || task === "")) {
alertstr += '- You must enter a valid value for the "Task"
field\n';
invalid++;
}
// standard text, hidden, password, or textarea box
var status = form.elements['status'].value;
if ( (! status.match(/^-?\s*[0-9]+$/)) ) {
alertstr += '- You must enter a valid value for the "Status"
field\n';
invalid++;
}
// standard text, hidden, password, or textarea box
var notes = form.elements['notes'].value;
if ( ((! notes && notes != 0) || notes === "")) {
alertstr += '- You must enter a valid value for the "Notes"
field\n';
invalid++;
}
if (invalid > 0 || alertstr != '') {
if (! invalid) invalid = 'The following'; // catch for
programmer error
alert(''+invalid+' error(s) were encountered with your
submission:'+'\n\n'+alertstr+'\n'+'Please correct these fields and try
again.');
// reset counters
alertstr = '';
invalid = 0;
return false;
}
return true; // all checked ok
}
//-->
</script><noscript><font color="red"><b>Please enable JavaScript or use
a newer browser</b></font></noscript><p></head><body
bgcolor="white"><h3>Form Build</h3><p>Fields shown in <b>bold</b> are
required.
<!-- Generated by CGI::FormBuilder v2.12 available from
www.formbuilder.org -->
<form action="form-build.cgi" method="post" onSubmit="return
validate(this);"><input name="_submitted" type="hidden" value="1"
/><input name="_sessionid" type="hidden" value="" /><table>
<tr valign="middle"><td align="left"><b>Category</b></td><td><input
name="category" type="text" /></td></tr>
<tr valign="middle"><td align="left"><b>Task</b></td><td><input
name="task" type="text" /></td></tr>
<tr valign="middle"><td align="left"><b>Status</b></td><td><input
name="status" type="text" /></td></tr>
<tr valign="middle"><td align="left"><b>Notes</b></td><td><input
name="notes" type="text" /></td></tr>
<tr valign="middle"><td colspan="2"><center><input name="_reset"
type="reset" value="Reset" /><input name="_submit" type="submit"
value="Submit" /></center></td></tr></table>
</form></body></html>


Perl v5.8.4 under linux
Modules in memory:
attributes;
Carp v1.02;
CGI v3.04;
CGI::FormBuilder v2.12;
CGI::Util v1.4;
CGITempFile;
constant v1.04;
DynaLoader;
Exporter v5.58;
Fh;
Internals;
Module::Versions::Report v1.02;
MultipartBuffer;
overload v1.01;
PerlIO;
PerlIO::Layer;
Regexp;
strict v1.03;
UNIVERSAL;
utf8;
vars v1.01;
warnings v1.03;
warnings::register v1.00;
[at Wed Sep 19 12:41:01 2007 (local) / Wed Sep 19 17:41:01 2007 (GMT)]

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Header files with "header.h" or <header.h> ?? mlt C++ 2 01-31-2009 02:54 PM
remove header line when reading/writing files RyanL Python 5 10-12-2007 06:39 AM
How to read a text file line by line and remove some line kaushikshome C++ 4 09-10-2006 10:12 PM
Calling cgi from cgi thru 'system' function. Different behaviour on browser v/s cmd line Shailan Perl 2 12-15-2003 04:26 PM



Advertisments