Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old August 3rd, 2000, 03:42 AM
MeijdenB MeijdenB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Alkmaar, The Netherlands
Posts: 123 MeijdenB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
Hi all,

I'm trying to write a Perl 5.005_03 script that returns a HTTP-header and prints something like Hello World. When I execute it on Red Hat Linux 6.1 it gives the output that I expect. However when I request that page in MSIE 4 on a different machine I get a 500 Internal Server Error. When I check the apache 1.3.9 logs on my Linux machine it first says "no such file or directory" and the second entry says premature end of script-headers.

Can anybody help me?

I checked the Perl path and priveledges on the file, they are okay.

The code looks something like this:

<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">code:</font><HR><pre>
#! /usr/bin/perl

my $sessiondid="";
my ($name,$value)=split(/=/,$ENV{'QUERY_STRING'});

$value=~tr/+/ /;
$value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$name=~tr/+/ /;
$name=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;

if ($name="session-id") {
$sessionid=$value;
}

open(INFILE,"</home/codes") or die;

$i=0;
@validSessionIds=();
while (<INFILE> ) {
@validSessionIds[$1]=substr($_,0,12);
$i++;
}

close(INFILE);

my $validation = 0;
foreach $x (@validSessionIds) {
if ($x eq $sessionid) {
$validation=1;
}
}

if ($validation) {
print "Set-Cookie: check=truen";
print "Status: 302 Movedn";
print "Location: <A HREF="http://somewhere.comn";" TARGET=_blank>http://somewhere.comn";</A>
print "Content-Type: text/htmlnn";
print "<HTML><HEAD></HEAD><BODYn";
print "Halleluja!n";
print "</BODY></HTML>n";
}
else {
print "Status: 302 Movedn";
print "Location: <A HREF="http://somewhereelse.com/n";" TARGET=_blank>http://somewhereelse.com/n";</A>
print "Content-Type: text/htmlnn";
print "<HTML><HEAD></HEAD><BODY>n";
print "Ohhh Noooo, You failed!n";
print "</BODY></HTML>n";
}

[/code]

It will retrieve a session-id from the query-string and compare it with some session-id's in a file. If the check succeeds you get a cookie and are redirected to one site. If the check fails you are redirected to some other site containing an error.

Thanks for your help,
Bas

[This message has been edited by MeijdenB (edited August 03, 2000).]

Reply With Quote
  #2  
Old August 3rd, 2000, 04:57 AM
Imo Imo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 33 Imo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 14
I suggest you try programming with the -w option after your #!/usr/bin/perl.

So #!/usr/bin/perl -w... this will give you more warnings etc.

Maybe try programming with strict on as well: use strict;


Reply With Quote
  #3  
Old August 3rd, 2000, 04:33 PM
JonLed JonLed is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Aug 2000
Location: Indiana
Posts: 614 JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level)JonLed User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 4 h 49 m 49 sec
Reputation Power: 14
all use strict; does is causes all kinds or problems if you don't define a variable before it tries to get used... that's not what's causing your problem.

As far as your problem goes, I don't know what to tell you. I'd try out the script, but my server's in crash mode today and I Apache refuses to restart, so F it .

Reply With Quote
  #4  
Old August 3rd, 2000, 05:10 PM
freebsd
Guest
Dev Shed Newbie (0 - 499 posts)
 
Posts: n/a  
Time spent in forums:
Reputation Power:
What are you trying to do with this...

open(INFILE,"</home/codes") or die;
$i=0;
@validSessionIds=();
while (<INFILE> ) { @validSessionIds[$1]=substr($_,0,12);
$i++;
}
close(INFILE);

>>my $sessiondid="";

Perhaps a mispell?

Reply With Quote
  #5  
Old August 4th, 2000, 01:19 AM
MeijdenB MeijdenB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2000
Location: Alkmaar, The Netherlands
Posts: 123 MeijdenB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 13
<BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by freebsd:
What are you trying to do with this...

open(INFILE,"</home/codes") or die;
$i=0;
@validSessionIds=();
while (<INFILE> ) { @validSessionIds[$1]=substr($_,0,12);
$i++;
}
close(INFILE);

>>my $sessiondid="";

Perhaps a mispell?
[/quote]

This file, /home/codes, is written by a different program. It contains some session-ids. With this while-loop I try to put those session-ids in an array. Although $1 should off course be $i. Typo's do happen some time , but that isn't the problem I guess.

Bas


Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > Premature end of scriptheaders

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap