www.webdeveloper.com
Results 1 to 6 of 6

Thread: HTTP Headers Problem: Perl & CGI on IIS 6.0

  1. #1
    Join Date
    Sep 2006
    Location
    Ipswich
    Posts
    88

    HTTP Headers Problem: Perl & CGI on IIS 6.0

    Hi,

    I'm working on a Perl CGI script to evaluate input from a form and then send a user to a specified page depending on whether the fields in the form are filled in correctly. So far the logic of the form works ok, it accepts values from a form and queries the values submitted against known values in a MySQL database.

    However, although the script coding checks out ok when the browser tries to render the out put of the script I am getting an error:

    "The specified CGI application misbehaved by not returning a complete set of HTTP headers."

    (I previously had a HTTP verb error but worked through this by configuring application mapping and web service extension mapping for Perl .pl & .cgi scripts).

    The code which should render is:

    Code:
    use warnings;
    use strict;
    
    use MOconnect;
    use MCSSconnect;
    use MNconnect;
    
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    use DBI;
    use CGI;
    
    my $query = new CGI;
    
    ################################################################
    # Multilpe DB queries and if/elsif constructs snipped                                                         #
    ################################################################
    
    else {
       my $url4 = '../../html/success.html';
       print $query->header("text/html");
       print $query->redirect($url4);
       print $query->start_html("CSS\: You Have Successfully Logged In");
       print $query->h1("APP\: You Have Successfully Logged In");
       print $query->end_html;
    }
    Can anyone offer a suggestion to overcome this error or improve the code?

    Thanks.

  2. #2
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    393
    Looks like you have output before the HTTP header. To prevent this, print HTTP headers as the very first thing in your script, in a BEGIN block:

    Code:
    BEGIN {
        $| = 1;    # this makes all output be sent immediately, without buffering
        print "Content-Type: text/html\n\n";
    }
    Then remove all $query->header calls from your script.

  3. #3
    Join Date
    Sep 2006
    Location
    Ipswich
    Posts
    88
    Hi Sixtease,

    Well, I tried this but I am still getting the same error? I have enclosed my code below, it's probably not very efficient, but at my level of knowledge I understand how it works (maybe will revise as I learn more), but I really am having trouble with this error....

    Code:
    #!/usr/bin/perl
    # perldoc_strict.cgi
    
    use warnings;
    use strict;
    
    use MOconnect;
    use MCSSconnect;
    use MNconnect;
    
    use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
    use DBI;
    use CGI;
    
    BEGIN {
           $| = 1;    # this makes all output be sent immediately, without buffering
           print "Content-Type: text/html\n\n";
    }
    
            my $query = new CGI;
    
            my $htmlservice_id = ('service_id');
    	my $htmluserName = ('userName');
    	my $htmlpassword = ('password');
    
    	my $ip_address = $ENV{'REMOTE_ADDR'};
    	my $calling_page = $ENV{'HTTP_REFERER'};
    
    my $dbdriver1  = $MOconnect::dbdriver;
    my $hostname1  = $MOconnect::hostname;
    my $port1      = $MOconnect::port;
    my $username1  = $MOconnect::username;
    my $password1  = $MOconnect::password;
    my $basename1  = $MOconnect::basename;
    my $tablename1 = $MOconnect::tablename;
    
    my $dbh1 = DBI->connect("dbi:$dbdriver1:$basename1:$hostname1:$port1",
                           $username1, $password1) || die print "Can't connect to database: #$DBI::errstr";
    
    my $sqlstatement1 = ("SELECT service_id FROM $tablename1 WHERE service_id='$htmlservice_id'");
    my $sth1 = $dbh1->prepare($sqlstatement1);
    $sth1->execute || die "Can't prepare statement: $DBI::errstr";
    
    my $sqlservice_id = $sth1->fetchrow_array;
    
    	my $dbdriver2  = $MCSSconnect::dbdriver;
    	my $hostname2  = $MCSSconnect::hostname;
    	my $port2      = $MCSSconnect::port;
    	my $username2  = $MCSSconnect::username;
    	my $password2  = $MCSSconnect::password;
    	my $basename2  = $MCSSconnect::basename;
    	my $tablename2 = $MCSSconnect::tablename;
    
    	my $dbh2 = DBI->connect("dbi:$dbdriver2:$basename2:$hostname2:$port2",
    	                       $username2, $password2) || die print "Can't connect to database: #$DBI::errstr";
    
    	my $sqlstatement2 = ("SELECT userName FROM $tablename2 WHERE userName='$htmluserName'");
    	my $sth2 = $dbh2->prepare($sqlstatement2);
    	$sth2->execute || die "Can't prepare statement: $DBI::errstr";
    
    	my $sqluserName = $sth2->fetchrow_array;
    
    	        my $dbdriver3  = $MCSSconnect::dbdriver;
    	        my $hostname3  = $MCSSconnect::hostname;
    	        my $port3      = $MCSSconnect::port;
    	        my $username3  = $MCSSconnect::username;
    	        my $password3  = $MCSSconnect::password;
    	        my $basename3  = $MCSSconnect::basename;
    	        my $tablename3 = $MCSSconnect::tablename;
    
    	        my $dbh3 = DBI->connect("dbi:$dbdriver3:$basename3:$hostname3:$port3",
    	                               $username3, $password3) || die print "Can't connect to database: #$DBI::errstr";
    
    	        my $sqlstatement3 = ("SELECT password FROM $tablename3 WHERE password='$htmlpassword'");
    	        my $sth3 = $dbh3->prepare($sqlstatement3);
    	        $sth3->execute || die "Can't prepare statement: $DBI::errstr";
    
    	        my $sqlpassword = $sth3->fetchrow_array;
    
    if ($htmlservice_id ne $sqlservice_id) {
       my $url1 = '../../undefined_service.html';
    print $query->redirect($url1);
    print $query->start_html("CSS\: Unidentified Service");
    print $query->h1("CSS\: The Service You Selected Does Not Exist On CSS");
    print $query->end_html;
    }
    	elsif ($htmluserName ne $sqluserName) {
    	   my $url2 = '../../check_username.html';
    	print $query->redirect($url2);
            print $query->start_html("CSS\: Check Username");
            print $query->h1("CSS\: Please Check Your Username");
    	print $query->end_html;
    	}
    	        elsif ($htmlpassword ne $sqlpassword) {
    	           my $url3 = '../../check_password.html';
    	        print $query->redirect($url3);
    	        print $query->start_html("CSS\: Check Password");
    	        print $query->h1("CSS\: Please Check Your Password");
    	        print $query->end_html;
    		}
    	                else {
    	                   my $url4 = '../../html/success.html';
    	                print $query->redirect($url4);
    	                print $query->start_html("CSS\: You Have Successfully Logged In");
    	                print $query->h1("CSS\: You Have Successfully Logged In");
    	                print $query->end_html;
    	        	}

  4. #4
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    393
    Hmm... weird. Try to put the begin block even before the use statements. Maybe using one of the modules produces some output (which would be very strange though). Or may it be a caching problem? Try to delete browser cache and reload the page.

  5. #5
    Join Date
    Sep 2006
    Location
    Ipswich
    Posts
    88
    Yes,

    Very weird. I confirmed perl is installed correctly on my machine by running a couple of scripts with both .CGI and .pl extensions. After trying the method you suggested I got a different error:

    "Can't locate MOconnect.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) at <path-to-scipt-snipped> line 12. BEGIN failed--compilation aborted at <path-to-scipt-snipped> line 12."

    Basically the modules I used hold values for the connections to various databases I have set up, and I didn't want to include all the values in the main script, thought it might be a possible security issue? This error sounds to me like I need to include any modules I create in either of the directories listed or add a directory to the @INC array, so for now the modules are in a recognised Perl directory and everything works fine!

    Thanks once again.

    Now I just need to figure out how to maintain session state for a user, I have heard using hidden fields or cookies might not be very secure, although I am configuriong my server to only accept https connections to this resource. What's your view on this?

  6. #6
    Join Date
    Oct 2007
    Location
    Vienna, Austria
    Posts
    393
    Glad we solved it. As regards session handling, cookies are the standard. Everybody uses them, including banks and renowned email providers. With https, everything should be OK. Just do yourself the favor of not reinventing the wheel and use a CPAN module.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles