Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Problems? Is your data what you think it is?
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Most esteemed monks:

I have been wrestling with a problem in a CGI script which is included in a .html file as #exec cgi="retrieve_password.pl". (".html" has been set to server-parsed html).

A form (method=GET) calls another html page, resulting in a GET query of "/retrieve_password.html?email=user@domain.com". Then the QUERY_STRING is passed along to retrieve_password.pl through the Apache sub-request.

However, upon output, the Content-type: text/html is visible on the webpage! I triple-checked, and I do not see my script outputting headers more than once. But if I edit the script and comment-out the line which prints the header, it produces an error.

It seems that if I comment-out my call to send_account() that the header no longer becomes visible. But why is this?

Any help you can provide would be most welcome.

#!/usr/bin/perl # database names, emails, subjects have been changed # to protect the innocent use strict; use CGI; use CGI::Carp qw(fatalsToBrowser); use Postgres; # old module, I know use Mail::Send; my $sql = db_connect("mydbname"); if (!$sql){ die "Unable to open database: $!\n"; } my $table = 'users'; my $q = new CGI; print $q->header; if($q->param('email') eq ''){ print $q->p(qq{<p>Please <a href="javascript:history.go(-1)">go ba +ck</a> and provide your account email address.</p>\n}); exit; } my $query = sprintf(q{SELECT email, namefirst, namelast, username, use +rpass from %s WHERE email ~ %s}, $table, qstr($q->param('email')) ); my $result = $sql->execute($query); my @data = $result->fetchrow(); my $email = $data[0]; if($email ne ''){ send_account(\@data); print $q->p( "Thank you! Your account information has been sent t +o " . $email ); print $q->p( qq{<a href="/login.php">Log In</a>} ); }else{ print $q->p(qq{<p>Sorry! No account found with that email address +. Please } . qq{<a href="javascript:history.go(-1)">go back</a> and try + again.</p>\n}); } sub qstr{ # this old Postgres module does not have its own quote() method. # this is a weak implementation, but better than nothing. (I think +) my ($str) = @_; $str =~ s#(\\)#/#sg; # replace backslashes with slashes $str =~ s/(['])/\\$1/; # escape single-quotes return qq{'$str'}; } sub send_account{ my ($matching_row) = @_; # Set Mail Headers my $mailout = new Mail::Send; $mailout->to( shift @{$matching_row} ); $mailout->subject("Online Registration"); $mailout->add('From', 'user@domain.com'); $mailout->add('Reply-To', 'user@domain.com'); # open up a mail filehandle my $mailfh = $mailout->open; # print mail body my $mailbody=<<END_OF_MAIL; Dear %s %s: Thank you for registering. Here is your account information: USERNAME: %s PASSWORD: %s Please keep this information safe. Your account is active, and you may log in any time to place your fi +rst order. Sincerely, Administrator END_OF_MAIL printf $mailfh $mailbody, @{$matching_row}; # close and send $mailfh->close; }

I realize that some of the code is not the most elegant, and you are welcome to provide corrections, but my most pressing need is this spurious display of the content-type header.

Oh, it may also be worth noting that there are other perl scripts included in the page in a similar fashion, and these do NOT show a visible content-type header, though they DO have a "print $q->header;" line.


In reply to CGI + SSI = extra content-type header? by Kozz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others imbibing at the Monastery: (6)
    As of 2014-04-21 10:11 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      April first is:







      Results (492 votes), past polls