Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Content -Type info is visible in browser window

Status
Not open for further replies.

Newposter

Technical User
May 9, 2002
735
0
0
US
OK, I just built a new server and it created a new problem for me.

Old server:
Windows 2000 Pro
Apache 1.3.3.1
ActiveState PERL 5.6.1

New server:
Windows 2000 Pro
Apache 2.2.1.5
ActiveState PERL 5.10
(and also has IIS installed but not yet configured).

This NEVER happened with the old server. With the new one, when I use an email form that runs a CGI script to create the email, and it finishes the script and loads a "success" page to the browser, the following is visible in the upper left of the browser window:

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

It is never present in any other HTML pages. The CGI script does contain and load the "sucess" message to the HTML pages that have this problem.

Is it an Apache bug, or configuration error, or is it a PERL issue? This will definitely be an issue with my customer. Thanks.

Newposter
"Good judgment comes from experience. Experience comes from bad judgment."
 
Hi

For now I would say, it is a server configuration problem. We need more information :
[ul]
[li]Response HTTP headers and the first few lines of the content[/li]
[li]Source code of the CGI script[/li]
[li]Apache configuration file(s)[/li]
[/ul]
You can inspect the HTTP headers using a tool :
[ul]
[li]Browser:
[ul]
[li]FireFox:
[ul]
[li]Live HTTP Headers[/li]
[li]FireBug[/li]
[li]Web Developer[/li]
[/ul]
[/li]
[li]Lynx[/li]
[li]Links[/li]
[li]W3M[/li]
[li]Explorer:
[ul]
[li]ieHTTPHeaders[/li]
[li]IEWatch[/li]
[/ul]
[/li]
[/ul]
[/li]
[li]tool:
[ul]
[li][tt]netcat[/tt][/li]
[li]PuTTY[/li]
[li][tt]telnet[/tt][/li]
[li][tt]Wget[/tt][/li]
[li][tt]cURL[/tt][/li]
[/ul]
[/li]
[/ul]

Feherke.
 
OK, I can post the Apache config and the GCI script, the first is quite long. Not sure what the HTTP response headers are.

I did right-click and View Source of the resulting page, and the "Content-type" line appears at the very top, before and outside of the <html> setting, if that helps.

The script writes the incoming email message to a .txt file and then generates the message to be sent, and if the email script runs without errors, continues on to call the success page and populate it with the success message from the script. In the script, this command appears just before cookie settings:

print "Content-type: text/html\n";

That would seem to be the only relevant part of the script (which was freeware that I did not author) to the error. I'll post the rest later, if you can enlighten me as to what the response HTTP headers are. I'm self-taught, learned as much as I need to, and it shows, I know. Thanks.

Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
Hi

Newposter said:
OK, I can post the Apache config and the GCI script, the first is quite long. [gray](...)[/gray] That would seem to be the only relevant part of the script (which was freeware that I did not author) to the error.
Then please post the script or the URL from where we can download it.

Regarding the configuration, you can shorten it by removing empty lines and the comments. Or see if you have [tt]ForceType[/tt] directive used somewhere.
Newposter said:
Not sure what the HTTP response headers are.
The HTTP requests ( user agent -> web server ) and HTTP responses ( web server -> user agent ) are composed by two parts : headers and body. The headers are telling to the communicating fellow how to interpret the body. The headers are colon ( : ) separated key-value pairs with optional parameters, delimited with newline marks. In certain circumstances, the body may be absent, but the headers are always present. Usually the headers are not displayed to the user, unless explicitly requested. That is why you have to use a tool, as I enumerated previously. I suggest to try Live HTTP Headers : install it, activate it, make the request then read what the extension captured.

Feherke.
 
Since the Content-type text does not appear when calling up the success page in the browser on its own, but only when the page is called by the PERL script, it must be something about the script that causes this. This is the CGI:


Code:
#!D:/PERL_510/bin/perl.exe
##############################################################################
##############################################################################
# Setup Begin
$cgiurl         = "[URL unfurl="true"]http://www.domain.com/cgi-bin/sendemail.cgi";[/URL] # THE URL OF CGI SCRIPT.
$filehead       = "C:/[URL unfurl="true"]www/htdocs/domain/";[/URL] # THE REAL PATH OF "*.htm", "*.txt" FILES. (YOU MAY CONTACT YOUR ISP FOR THIS PATH)
$guestbookfile  = "email.txt"; # DATABASE OF MESSAGES
$mainpagefile   = "index_temp.htm";    # MAIN PAGE OF YOUR GUESTBOOK
$succpagefile   = "ack.htm";      # THE PAGE AFTER LEAVING MESSAGE
$errorpagefile  = "error.htm";     # THE PAGE TO SHOW ERROR MESSAGE
$managepagefile = "manage.htm";    # THE PAGE OF CONTROL PANEL

$allow_html     = 2;   # 1=ALLOWS VISTORS TO USE HTML. 2=DISABLE IT.
$perpage        = 50;  # MAXMIUM MESSAGES FOR EACH PAGE
$manageperpage  = 250; # MAXIMUM MESSAGES OF CONTROL MODE
$time_miss      = +0; # TIMER

$masteremail = "email\@domain.com"; # YOUR E-MAIL ADDRESS
$fromemail   = "email\@domain.com"; # YOUR E-MAIL ADDRESS
$sendtomaster= 1;                          # 1=ENABLE 0=DISABLE (FUNCTION OF AUTO NOTICE)
$sendtoguest= 0;
# END
#############
#$|=1;

&get_form;
&set_var;

$manage=0;
if (($manageid ne "") && ($managepassword ne "")) {
   if ($manage{$manageid} eq $managepassword) {
      $manageinfo="&manageid=$manageid&managepassword=$managepassword";
      $manage=1;
      $perpage=$manageperpage;
   }
}

print "Content-type: text/html\n";
print "Set-Cookie: cookieusername=$username; expires=30-Dec-99 GMT\n" if (($username ne "") && ($cookieusername ne $username));
print "Set-Cookie: cookieuseremail=$useremail; expires=30-Dec-99 GMT\n" if (($useremail ne "") && ($cookieuseremail ne $useremail));
print "Set-Cookie: cookieuserurl=$userurl; expires=30-Dec-99 GMT\n" if (($userurl ne "") && ($cookieuserurl ne $userurl));
print "\n";

$cookieusername=$username if (($username ne "") && ($cookieusername ne $username));
$cookieuseremail=$useremail if (($useremail ne "") && ($cookieuseremail ne $useremail));
$cookieuserurl=$userurl if (($userurl ne "") && ($cookieuserurl ne $userurl));

if ($job eq "add") {
   &guestbook_add;
   exit 0;
}
elsif ($job eq "manage") {
   &guestbook_manage;
   exit 0;
}
elsif (($job eq "erase") && ($manage==1)) {
   &guestbook_erase;
   exit 0;
}

@mainpagefile=&readtxtfile("$filehead$mainpagefile");
foreach (@mainpagefile) { 
   if ($_ =~ /<!--listhere-->/) {
      if ($page eq "") {$page=1;}

      @guestbook=&readtxtfile("$filehead$guestbookfile",1);
      @guestbook=sort @guestbook;
      if ($searchword ne "") {
         @temp=();
         foreach (@guestbook) {
            if ($_ =~ /$searchword/i) {
               push(@temp,"$_");
            }
         }
         @guestbook=@temp;
      } 
      $totalguestbook=$#guestbook+1;
      splice(@guestbook,0,$#guestbook-$page*$perpage+1);
      splice(@guestbook,$#guestbook-($page-1)*$perpage+1,($page-1)*$perpage);

      print "<form method=post action=$cgiurl?job=erase&searchword=$searchword&page=$page$manageinfo>\n" if ($manage==1);
      if ($#guestbook>=0) {
         for ($i=$#guestbook;$i>=0;$i--) {
             ($mark,$chkdaten,$chktimen,$chkusername,$chkuserip,$chkuseremail,$chkuserurl,$chkcomments,$markend,$last)=split(/¡ü/,$guestbook[$i]);
             $guestbook[$i]=~ s/$searchword/<font color=ff0000>$searchword<\/font>/gi if ($searchword ne "");     
             ($mark,$chkdaten1,$chktimen1,$chkusername1,$chkuserip1,$chkuseremail1,$chkuserurl1,$chkcomments1,$markend,$last)=split(/¡ü/,$guestbook[$i]);
             if (($mark eq "guestbook") && ($markend eq "end")) {
                $temp1="";
                $temp1="<font face=\"verdana\" size=\"2\" color=\"#FF0000\">Posted Today</font>" if ($chkdaten eq $daten);
                $temp2=""; 
                $temp2="<input type=checkbox name='guestbookmark' value='$chkdaten¡ü$chktimen'>" if ($manage==1);
                print "$temp1\n"; 
                print "<table border=0 cellspacing=0 cellpadding=0>\n";
                print "<tr><td>$temp2<font face=\"verdana,arial\" size=\"2\"><b>$chkusername1</b> visited on $chkdaten1 at $chktimen1</i></font></td></tr>\n";
                print "<tr><td>\n";
                if (($chkuseremail ne "") || ($chkuserurl ne "")) {
                   print "<font face=\"verdana,arial\" size=\"2\"><b>Email:</b> <a href=mailto:$chkuseremail>$chkuseremail1</a></font><br>\n" if ($chkuseremail ne "");
                   print "<font face=\"verdana,arial\" size=\"2\"><b>Web Site:</b> <a href=$chkuserurl target='others'>$chkuserurl1</a></font><br>\n" if ($chkuserurl ne "");
                }
                print "<font face=\"verdana,arial\" size=\"2\"><b>$chkcomments1</b></font><br>\n";
                print "</td></tr></table><br>\n\n";
		print "<hr>" 
             }
         }
      }
      print "<input type=submit value='DELETE'>\n</form>\n" if ($manage==1);
   }
   elsif ($_ =~ /<!--otherpagehere-->/) {
      $i=1;
      $j=$totalguestbook;
      while ($j>0) {
         print " ";
         print "<a href=$cgiurl?page=$i&searchword=$searchword$manageinfo>" if ($page != $i); 
         print "$i"; 
         print "</a>" if ($page != $i);
         $j=$j-$perpage; 
         $i++;
      }
   }
   else {
      $_ =~ s/\$cgiurl/$cgiurl/g;
      $_ =~ s/\$cookieusername/$cookieusername/g;
      $_ =~ s/\$cookieuseremail/$cookieuseremail/g;
      $_ =~ s/\$cookieuserurl/$cookieuserurl/g;
      $_ =~ s/\$manageinfo/$manageinfo/g;
      $_ =~ s/\$searchword/$searchword/g;
      print "$_";
   }
}
exit 0;
##########
sub guestbook_add {
&checkempty($username,"Your name cannot be blank.");
&checkempty($useremail,"Your email address cannot be blank.");
&checkempty($comments,"Your message cannot be blank.");
     
open(GUESTBOOK,">>$filehead$guestbookfile");
print GUESTBOOK "guestbook¡ü$daten¡ü$timen¡ü$username¡ü$userip¡ü$useremail¡ü$userurl¡ü$comments¡üend¡ü\n";
close(GUESTBOOK);

#webmaster email notice
send_mail($to, $from, $subject, $comments, $username, $userip, $useremail, $userurl, $daten, $timen);

sub send_mail {

use CGI qw(:standard);
     use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
     use Net::SMTP;
     use MIME::Base64;
     
     print header;
     print start_html("Environment");
     #Keep debug off in order for web and email to both work correctly on large messages
     $smtp = Net::SMTP->new(
         'domain.com' ,# may need a helo parameter here on some servers
          Timeout => 30,
          Debug   => 0,
      );
     $smtp->datasend("AUTH LOGIN\n");
     $smtp->response();
     #  -- Enter sending email box address username below.  We will use this to login to SMTP --
     $smtp->datasend(encode_base64('email@domain.com') );
     $smtp->response();
     #  -- Enter email box address password below.  We will use this to login to SMTP --
     $smtp->datasend(encode_base64('password') );
     $smtp->response();

    $smtp->mail($fromemail);
    $smtp->to($masteremail);
    $smtp->to($fromemail);

    $smtp->data();
    $smtp->datasend("To: $masteremail\n");
    $smtp->datasend("From: domain.com\n");
    $smtp->datasend("Subject: New email sent to domain.com\n");
    $smtp->datasend("\n");
    $smtp->datasend("\n");
    $smtp->datasend("\n");
    $smtp->datasend("A copy of the message can be found below\n");
    $smtp->datasend("======================================\n");
    $smtp->datasend("   NAME: $username($userip) at $daten($timen)\n");
    $smtp->datasend("   EMAIL: $useremail\n");
    $smtp->datasend("   \n");
    $smtp->datasend("   $comments\n");
    $smtp->datasend("   \n"); 

    $smtp->dataend();
    $smtp->quit();
}
&guestbook_succ("Your message has been successfully sent.");
}
##########
sub guestbook_manage {
@managepagefile=&readtxtfile("$filehead$managepagefile");
foreach (@managepagefile) {
   $_ =~ s/\$cgiurl/$cgiurl/g;
   print "$_";
}
}
##########
sub guestbook_erase {
if ($guestbookmark ne "") {
   @guestbook=&readtxtfile("$filehead$guestbookfile",1);
   @guestbook=sort @guestbook;

   open(GUESTBOOK,">$filehead$guestbookfile");
   foreach (@guestbook) {
      ($mark,$chkdaten,$chktimen,$chkusername,$chkuserip,$chkuseremail,$chkuserurl,$chkcomments,$markend,$last)=split(/¡ü/,$_);
      if (($mark eq "guestbook") && ($markend eq "end")) {
         if (!($guestbookmark =~ /$chkdaten¡ü$chktimen/)) {
            print GUESTBOOK "$_"; 
         }
      }
   }
   close(GUESTBOOK);
}
&guestbook_succ("DELETED!");
}
##########
sub guestbook_succ {
@succpagefile=&readtxtfile("$filehead$succpagefile");
foreach (@succpagefile) {
   $_ =~ s/\$cgiurl/$cgiurl/g;
   $_ =~ s/\$manageinfo/$manageinfo/g;
   $_ =~ s/\$searchword/$searchword/g;
   $_ =~ s/\$page/$page/g;
   $_ =~ s/\$succmessage/$_[0]/g;
   print "$_";
}
}
##########
sub set_var {
$job            =&get_var('job'            ,'\n|¡ü');
$username       =&get_var('username'       ,'\n|"|<|>|\&|;|\?|¡ü');
$useremail      =&get_var('useremail'      ,'\n|¡ü| ');
$userurl        =&get_var('userurl'        ,'\n|¡ü| ');
$cookieusername =&get_var('cookieusername' ,'\n|"|<|>|\&|;|\?|¡ü');
$cookieuseremail=&get_var('cookieuseremail','\n|¡ü| ');
$cookieuserurl  =&get_var('cookieuserurl'  ,'\n|¡ü| ');
$comments       =&get_var('comments'       ,'¡ü');
$searchword     =&get_var('searchword'     ,'\n|¡ü');
$page           =&get_var('page'           ,'\n|¡ü');
$guestbookmark  =&get_var('guestbookmark'  ,'\n');
$manageid       =&get_var('manageid'       ,'\n|"|<|>|\&|;| |\?|¡ü');
$managepassword =&get_var('managepassword' ,'\n|"|<|>|\&|;| |\?|¡ü');
$smtp_username  =&get_var('smtp_username'       ,'\n|"|<|>|\&|;|\?|¡ü');
$smtp_password  =&get_var('smtp_password'       ,'\n|"|<|>|\&|;|\?|¡ü');

$useremail="" if (!($useremail =~ /.*\@.*\..*/));
$userurl  ="" if (!($userurl   =~ /.*\:.*\..*/ ));
$comments =~ s/\n/<br>/g;

$cookieuseremail=""        if (!($cookieuseremail =~ /.*\@.*\..*/));
$cookieuserurl  ="[URL unfurl="true"]http://"[/URL] if (!($cookieuserurl   =~ /.*\:.*\..*/ ));

$userip=$ENV{'REMOTE_ADDR'};

($secn,$minn,$hourn,$dayn,$monn,$yearn,$weekn,$yeardayn,$isdst) = localtime(time+(3600*$time_miss));
$monn=$monn+1;
if ($monn<10)  {$monn="0$monn";}
if ($dayn<10)  {$dayn="0$dayn";}
if ($hourn<10) {$hourn="0$hourn";}
if ($minn<10)  {$minn="0$minn";}
if ($secn<10)  {$secn="0$secn";}
$yearn=$yearn+1900;
$daten="$yearn/$monn/$dayn";
$timen="$hourn\:$minn\:$secn";
}


############
sub get_form {
@querys = split(/&/, $ENV{'QUERY_STRING'});
foreach (@querys) {
  ($name,$value) = split(/=/, $_);
  $value = &decode($value);
  $value = &filterhtml($value);
  &setvaluetoform($name, $value); 
}

read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach (@pairs) {
  ($name, $value) = split(/=/, $_);
  $value = &decode($value);
  $value = &filterhtml($value);
  &setvaluetoform($name, $value); 
}

@cookies = split(/; /, $ENV{HTTP_COOKIE});
foreach $cookies (@cookies) {
   ($name, $value) = split(/=/, $cookies);
   $value = &decode($value);
   $value = &filterhtml($value);
   &setvaluetoform($name, $value); 
}
}
##########
sub decode {
local($return)=$_[0];
$return =~ tr/+/ /;
$return =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
return $return;
}
##########
sub filterhtml {
local($return)=$_[0];
$return =~ s/<!--(.|\n)*-->//g;
if ($allow_html != 1) {
   $return =~ s/<([^>]|\n)*>//g;
   $return =~ s/<//g;
}
return $return;
}
##########
sub setvaluetoform {
if ($FORM{$_[0]}) {
   $FORM{$_[0]}="$FORM{$_[0]}¡±$_[1]";
}
else {
   $FORM{$_[0]}=$_[1];
}
}
#########
sub get_var {
local($return)="";
$return="$FORM{$_[0]}" if ($FORM{$_[0]});
$return=~ s/$_[1]//g;
return $return;
}
#########
sub readtxtfile {
open(READTXTFILE,"$_[0]");
@readtxtfile=<READTXTFILE>;
close(READTXTFILE);
return @readtxtfile;
}
#############
sub checkempty {
local($chkval)=$_[0];
$chkval =~ s/ |<br>|\n//g;
&error($_[1]) if ($chkval eq "");
}
##########
sub error {
@errorpagefile=&readtxtfile("$filehead$errorpagefile");
foreach (@errorpagefile) {
   $_ =~ s/\$errormessage/$_[0]/g;
   print "$_";
}
exit 0;
}

  This is the HTML code behind the success page ack.htm:

<HEAD>
<SCRIPT LANGUAGE="JavaScript">
function closeack() {
resultsWindow = window.close("ack.htm");
}
</SCRIPT>
</head>

<BODY BGCOLOR="#FFFFFF"  onLoad='resizeTo(550,500)'>
<CENTER><H1><CENTER><FONT SIZE="4">$succmessage</FONT></CENTER></H1>
<form><input type=button value="Close" onClick="closeack();"></form>
</CENTER>
</BODY>

Newposter
"Good judgment comes from experience. Experience comes from bad judgment.
 
Hi

That is a strange script. It uses the [tt]CGI[/tt] module, but instead of using a [tt]CGI[/tt] object's methods, it declares all kind of functions with similar ( but weaker ) functionality.

And that is the problem. This line also output HTTP headers :
that script said:
Code:
[COLOR=gray silver] 151 [/color]     [b]print[/b] header[teal];[/teal]
Try to comment out that line, the script should work correctly without that too.

Note that not only the Perl is strange there, the JavaScript too. The [tt]window.close()[/tt] method has no parameter. I would seriously think to replace that entire script.

Feherke.
 
That was it, thank you!

Yes, the script is a hodge-podge. I used a 3rd-party host who had that freeware script offered to create an email form, and when my ISP required email authentication, I had to find/write code to embed the username and password. That's where the use CGI qw, Print Header and print start_html part came from, some working code that I found that would enable authentication. I'll have to clean it up at some point.

The Javascript was something I found in Googling to find script to make a Window Close button.

Newposter
&quot;Good judgment comes from experience. Experience comes from bad judgment.&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top