Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 891
  • Last Modified:

I got CGI Header Error whe i execute my perl script

I have a perl script to get a database value and print on browser.This script is running successfully Linux Server.But when i run this script in windows server it gives HTTP header error.i use WINDOWS 2003 IIs 6.0 web server and Perl 5.8.8 and mysql 5.0.
#!C:/bin/perl.exe  -w
use DBI;
#definition of variables
$db="music";
$host="localhost";
$user="username";
$password="pass";
 
 
print "Content-type:text/html\n\n";
 
#connect to MySQL database
my $dbh   = DBI->connect ("DBI:mysql:database=$db:host=$host",
                          $user,
                          $password) 
                          or die "Can't connect to database: $DBI::errstr\n";
 
#prepare the query
my $sth = $dbh->prepare( "SELECT * FROM trackinfo");
 
#execute the query
$sth->execute( );
## Retrieve the results of a row of data and print
print "\tQuery results:\n================================================\n";
 
while ( my @row = $sth->fetchrow_array( ) )  {
     print "@row\n";
}
warn "Problem in retrieving results", $sth->errstr( ), "\n"
        if $sth->err( );
 
exit;

Open in new window

0
imidms
Asked:
imidms
1 Solution
 
FishMongerCommented:
Are you sure that IIS is configured to execute Perl scripts?

Do you have other Perl scripts that are working as expected, or do they all have this problem?

Have you checked the IIS log to see if it provides any clues to the problem?

Change the beginning of the script to this and report back with the exact error message.

#!C:/bin/perl.exe  -w
 
use CGI::Carp qw/FatalsToBrowser/;
use DBI;
#definition of variables

Open in new window

0
 
TintinCommented:
Best to use the CGI module as some IIS setups require NPH.

Change the top of your script to
use DBI;
use CGI::Carp 'fatalsToBrowser';
use CGI ':standard';
 
print header;

Open in new window

0
 
imidmsAuthor Commented:
Thanks for your reply,
Actually some the programs are working but most of the programs is  simply print the same header error.
could you suggest  possible configuration errors and server errors.Also some program which is using session are gives some error

mkdir C:/: File exists at C:/Program Files/SWsoft/Plesk/Additional/Perl/site/lib/CGI/Session/Driver/file.pm line 27


#!C:\Program Files\SWsoft\Plesk\Additional\Perl\bin\perl.exe
use CGI qw/:standard/;
use LWP::UserAgent;
use HTTP::Request qw(GET POST);
use HTTP::Headers;
 
use CGI::Cookie;
use CGI::Session;
 
use CGI::Carp qw(fatalsToBrowser);
 
my $q=new CGI;
 
my $c=new CGI::Cookie;
 
my $cIP = $ENV{'REMOTE_ADDR'} ;
 
# replace this value with license key
my $license_key ="mykey";
my $ua = LWP::UserAgent->new(timeout =>10);
 
my $h = HTTP::Headers->new;
 
$h->content_type('application/x-www-form-urlencoded');
 
my $request = HTTP::Request->new('POST','http://maxmind.com:8010/a',
                                 $h,"l=$license_key&i=$cIP");
my $res = $ua->request($request);
 
my $content = $res->content;
#print "Content-type: text/html\n\n" ;
############ again send request	#######
if($content eq "")
{
 sleep(1);
 
 $request = HTTP::Request->new('POST','http://maxmind.com:8010/a', 
                               $h,"l=$license_key&i=$cIP");        
 $res = $ua->request($request);                                    
                                                                   
 $content = $res->content;                                         
}
if($content eq "")
{
 sleep(1);
 
 $request = HTTP::Request->new('POST','http://maxmind.com:8010/a', 
                               $h,"l=$license_key&i=$cIP");        
 $res = $ua->request($request);                                    
                                                                   
 $content = $res->content;                                         
}
if($content eq "")
{
	$content="Server-Error";
}
 
my $session = "" ;
 
my $sid = "" ;
 
$sid = _Checkcookie();
 
if($sid eq "")
{
 $session = new CGI::Session("driver:File", $q, {Directory=>'/tmp'});
 
 my $server = $ENV{'HTTP_HOST'};
 
 my $path = "/";
 
 $sid = $session->id();
 
 print "Set-Cookie: CGISESSID\=$sid; path\=$path;domain\=$server\n" ;
}
else
{
 $session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
}
 
my $cFlag = 0 ;
 
my $referer=$q->param('referer');
 
my $albumid=$q->param('albumid');
 
my $action=$q->param('action');
 
my $shopping_info=$session->param('shopping_info');
 
my %shopping_info=%{$shopping_info};
 
$shopping_info{geo}=$content; 
 
if($referer eq "dinamalar"){
$shopping_info{referer}="dinamalar";
}
else{$shopping_info{referer}="";}
 
$session->param("shopping_info",\%shopping_info);
 
$session->expire('+12h');
 
if($action eq "direct"){
print $q->redirect(-uri=>'http://www.imi.in/cgi-bin/elearning/query/el_alb_details.pl?albumid=$albumid&action=geo',
                           -nph=>1,
                           -status=>302);
#print "Status: 302 Moved", "\r\n","Location: http://74.55.90.196/cgi-bin/elearning/query/el_alb_details.pl?albumid=$albumid&action=geo", "\r\n\r\n";
exit;
}
 
#print 'Status: 302 Moved', "\r\n",'Location:/cgi-bin/elearning/query/el_show_cat.pl', "\r\n\r\n"; 
 
print $q->redirect(-uri=>'http://www.imi.in/cgi-bin/elearning/query/el_show_cat.pl',
                           -nph=>1,
                           -status=>302);
 
exit;
 
sub _Checkcookie{
 
my %cookies=fetch CGI::Cookie;
 
my $name=$cookies{CGISESSID};
 
my @temp=split(/CGISESSID\=/,$name);
 
my @temp1=split(/;/,$temp[1]);
 
return $temp1[0];
}

Open in new window

0
 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

 
FishMongerCommented:
This is an entirely separate issue from your original question.  It would be best to separate these issues into 2 separate questions.
0
 
FishMongerCommented:
It appears that both of these separate issues have a couple things in common.  The first being that they are not running under strictures i.e they're missing

use strict;

Also, it's better to use/load the warnings pragma instead of  the -w switch as you have in your first code snippet.

use warnings;

You haven't specified the exact error message that you're receiving, but if you're receiving a "500 internal server error then that's caused by the script sending output, usually an error message, before outputting the headers.  If you add the line that I and Tintin suggested to the beginning of your script(s) (use Tintin's, mine had a slight typo), it should output a more descriptive error message in the browser.
0
 
imidmsAuthor Commented:
#!C:\Program Files\SWsoft\Plesk\Additional\Perl\bin\perl.exe
use CGI ':standard';
use LWP::UserAgent;
use HTTP::Request 'GET POST';
use HTTP::Headers;
use warnings;

use Cwd;

use CGI::Cookie;
 
use CGI::Carp 'fatalsToBrowser';

my $q=new CGI;

my $c=new CGI::Cookie;
 
my $cIP = $ENV{'REMOTE_ADDR'} ;

# replace this value with license key
my $license_key ="mykey";
 
my $ua = LWP::UserAgent->new(timeout =>10);

my $h = HTTP::Headers->new;

$h->content_type('application/x-www-form-urlencoded');

my $request = HTTP::Request->new('POST','http://maxmind.com:8010/a',
                                 $h,"l=$license_key&i=$cIP");
my $res = $ua->request($request);

my $content = $res->content;
#print "Content-type: text/html\n\n" ;
############ again send request      #######
if($content eq "")
{
 sleep(1);

 $request = HTTP::Request->new('POST','http://maxmind.com:8010/a',
                               $h,"l=$license_key&i=$cIP");        
 $res = $ua->request($request);                                    
                                                                   
 $content = $res->content;                                        
}
if($content eq "")
{
 sleep(1);
 
 $request = HTTP::Request->new('POST','http://maxmind.com:8010/a',
                               $h,"l=$license_key&i=$cIP");        
 $res = $ua->request($request);                                    
                                                                   
 $content = $res->content;                                        
}
if($content eq "")
{
      $content="Server-Error";
}

 
my $cFlag = 0 ;

my $referer=$q->param('referer');

my $albumid=$q->param('albumid');

my $action=$q->param('action');

 
my %shopping_info=%{$shopping_info};

$shopping_info{geo}=$content;
 
if($referer eq "dinamalar"){
$shopping_info{referer}="dinamalar";
}
else{$shopping_info{referer}="";}
 
if($action eq "direct"){
print $q->redirect(-uri=>'http://74.55.90.196/cgi-bin/elearning/query/el_alb_details.pl?albumid=$albumid&action=geo',
                           -nph=>1,
                           -status=>302);
 exit;
}


print $q->redirect(-uri=>'http://74.55.90.196/cgi-bin/elearning/query/el_show_cat.pl',
                           -nph=>1,
                           -status=>302);

exit;

Please debug this code.if you find any error please let me know.
 
0
 
Adam314Commented:
Add this as the second line in your program(the first beginning with #!), which was suggested earlier.  

use CGI::Carp 'fatalsToBrowser';

Open in new window

0
 
FishMongerCommented:
Line 81 has a problem.  After you add the CGI::Carp line that we've suggested, take a close look at problematic line.
0
 
imidmsAuthor Commented:
Thank you so much that problem has sorted but i have some other problem in session module.i have use session in the same program But it says permission denied error

#!C:\Program Files\SWsoft\Plesk\Additional\Perl\bin\perl.exe
use CGI::Carp 'fatalsToBrowser';
use CGI ':standard';
use LWP::UserAgent;
use HTTP::Request 'GET POST';
use HTTP::Headers;
use warnings;
use Cwd;
use CGI::Session;
use CGI::Cookie;
 

my $q=new CGI;

my $c=new CGI::Cookie;
 
my $cIP = $ENV{'REMOTE_ADDR'} ;

# replace this value with license key
my $license_key ="mykey";
 

my $ua = LWP::UserAgent->new(timeout =>10);

my $h = HTTP::Headers->new;

$h->content_type('application/x-www-form-urlencoded');

my $request ='';

$request=HTTP::Request->new('POST','http://maxmind.com:8010/a',
                                 $h,"l=$license_key&i=$cIP");
my $res = $ua->request($request);

my $content = $res->content;
#print "Content-type: text/html\n\n" ;
############ again send request      #######
if($content eq "")
{
 sleep(1);

 $request = HTTP::Request->new('POST','http://maxmind.com:8010/a',
                               $h,"l=$license_key&i=$cIP");        
 $res = $ua->request($request);                                    
                                                                   
 $content = $res->content;                                        
}
if($content eq "")
{
 sleep(1);
 
 $request = HTTP::Request->new('POST','http://maxmind.com:8010/a',
                               $h,"l=$license_key&i=$cIP");        
 $res = $ua->request($request);                                    
                                                                   
 $content = $res->content;                                        
}
if($content eq "")
{
      $content="Server-Error";
}


 my $session = "" ;

my $sid = "" ;

$sid = _Checkcookie();
 
if($sid eq "")
{
 $session = new CGI::Session("driver:File", $q, {Directory=>'C:/Inetpub/vhosts/imi.in/cgi-bin/tmp'});

 my $server = $ENV{'HTTP_HOST'};

 my $path = "/";

 $sid = $session->id();

 print "Set-Cookie: CGISESSID\=$sid; path\=$path;domain\=$server\n" ;
}
else
{
 $session = new CGI::Session(undef, $sid, {Directory=>'/tmp'});
}


my $cFlag = 0 ;

my $referer=$q->param('referer') || '';

my $albumid=$q->param('albumid') || '';

my $action=$q->param('action') || '';
 
my $shopping_info=$session->param('shopping_info');

my %shopping_info=%{$shopping_info};

$shopping_info{geo}=$content;
 
if($referer eq "dinamalar"){
$shopping_info{referer}="dinamalar";
}
else{$shopping_info{referer}="";}

$session->param("shopping_info",\%shopping_info);
 
$session->expire('+12h');

 
if($action eq "direct"){
print $q->redirect(-uri=>'http://74.55.90.196/cgi-bin/elearning/query/el_alb_details.pl?albumid=$albumid&action=geo',
                           -nph=>1,
                           -status=>302);
print 'Status: 302 Moved', "\r\n",'Location:http://74.55.90.196/cgi-bin/elearning/query/el_alb_details.pl?albumid=$albumid&action=geo', "\r\n\r\n";

 exit;
}

print 'Status: 302 Moved', "\r\n",'Location:http://74.55.90.196//cgi-bin/elearning/query/el_show_cat.pl', "\r\n\r\n";

exit;

 sub _Checkcookie{

my %cookies=fetch CGI::Cookie;

my $name=$cookies{CGISESSID};

my @temp=split(/CGISESSID\=/,$name);

my @temp1=split(/;/,$temp[1]);

return $temp1[0];
}

My error

mkdir /: Permission denied at C:/Program Files/SWsoft/Plesk/Additional/Perl/site/lib/CGI/Session/Driver/file.pm line 27

Actually i have use File driver to  store session ID so i store in 'C:/Inetpub/vhosts/imi.in/cgi-bin/tmp' path but it says permission denied problem.

Please help on this

Regards
Rajiv
0

Featured Post

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now