#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    15
    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).]
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 1999
    Posts
    33
    Rep Power
    16
    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;

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Aug 2000
    Location
    Indiana
    Posts
    614
    Rep Power
    15
    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 .
  6. #4
  7. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    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?
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2000
    Location
    Alkmaar, The Netherlands
    Posts
    123
    Rep Power
    15
    <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


IMN logo majestic logo threadwatch logo seochat tools logo