CGI: End of script output before headers

786 views
Skip to first unread message

clipper6

unread,
Feb 18, 2014, 4:14:53 AM2/18/14
to harbou...@googlegroups.com
I got this page which my program generates. But everytime I click a link I get this error:

Server error!

The server encountered an internal error and was unable to complete your request.

Error message:
End of script output before headers: my-web.cgi

Error 500


Why was it able to generate my index page but when I click a link I get an error? I extended tipcgi and borrowed some code from html.prg.

Here a snippet of my production code:

#include "hbclass.ch"

procedure Main()
    local request_method := "", b := ""
    local HTML := XCGI():New()
   
    request_method := Upper( HTML:REQUEST_METHOD )
       
    do case
    case request_method == "GET"
        if HTML:QUERY_STRING == ""
       
            PageIndex()
           
        elseif HTML:QUERY_STRING == "request=about"
            test_query_string( HTML:QUERY_STRING )           
        end if
       
    case request_method == "POST"   
   
    endcase
   
    return
*end Main

/****************************************************************************/
procedure test_query_string( query_string )
    local HTML := XCGI():New()
   
    HTML:label( 10, 10, 300, 25, "query_string => " + query_string, 'l_reg_login', NIL, 15 )
    HTML:label( 40, 10, 300, 25, '<a href="?request=about">ready</a> ...</body></html>', 'l_1', NIL, 15 )
      
    HTML:Generate()
    HTML:ShowResult()

*end test_query_string

....

METHOD Generate() CLASS XCGI

   ::Content := ;
    '<!DOCTYPE html>' + hb_eol() + ;
    '<html xmlns="http://www.w3.org/1999/xhtml">' + hb_eol() + ;
      "<head>" + hb_eol() + ;
      "<title>" + ::Title + "</title>" + hb_eol() +;
      ::Head + hb_eol() + ;
      "</head>"+ hb_eol() + ;
      '<body ' + ::BodyEvent + ' link="' + ::LinkColor + '" id="' + ::BodyID + '" bgcolor="' + ::BGColor + '" '  + ;
       'vlink="' + ::vLinkColor + '">' +                      + hb_eol() + ;
      ::Body                                                 + hb_eol() + ;
      "</body>" + hb_eol() + ;
      "</html>" + + hb_eol()
     
    // ::FormName 
    //'<body OnLoad="document.myform.mytextfield.focus();">' + hb_eol() + ;
   RETURN Self

METHOD ShowResult() CLASS XCGI

   OutStd( ;
        ;//      "HTTP/1.0 200 OK" + hb_eol() + ;
        "CONTENT-TYPE: TEXT/HTML"  + hb_OSNewLine() + hb_OSNewLine() + ;
        ::Content )

   //OutStd( ::Content )

   RETURN Self

Message has been deleted

clipper6

unread,
Feb 18, 2014, 4:55:19 AM2/18/14
to harbou...@googlegroups.com
I tried hand coding the html tag instead of generating this on the fly but I still get the same error. I simply called pagedbg(). It loads okay the first time but when i click Home or any link for that matter I get a server error. See code below:



#include "hbclass.ch"

procedure Main()
    local request_method := "", b := ""
    local HTML := XCGI():New()
   
    request_method := Upper( HTML:REQUEST_METHOD )
       
    do case
    case request_method == "GET"
        if HTML:QUERY_STRING == ""
       
            pagedbg()

           
        elseif HTML:QUERY_STRING == "request=about"
           
            pagedbg()

           
        end if
       
    case request_method == "POST"   
   
    endcase
   
    return
*end Main   

procedure pagedbg()
    local b := ""

    b := ;
    "Content-type: text/html" + hb_OSNewLine() + hb_OSNewLine() + ;
    '<html>' + ;
    '<head>' + ;
    '<title>PCHC Web</title>' + ;
    '<link rel="stylesheet" type="text/css" href="/css/pchc-web.css">' + ;
    hb_OSNewLine() + ;
    '</head>' + ;
    '<body OnLoad="document.LogInForm.username.focus();" link="#0000FF" id="body_id_999" bgcolor="#F3F9EB" vlink="#FF0000">' + ;
    '<img id="pchc_logo_1" src="/img/bg_rss1.jpg" alt="pchc_logo_1" style = "position: absolute; top: 101px; left: 101px"/>' + ;
    '<img id="pchc_logo_2" src="/img/bg_rss2.jpg" alt="pchc_logo_2" style = "position: absolute; top: 101px; left: 554px"/>' + ;
    '<DIV class="roundcorner" name="hmenu" id="hmenu" style="position:absolute; top:33px; left:101px; width:420px; height:25px"><font size="4" color="black"><a href="?request=home">Home*</a> &nbsp &nbspAbout Us &nbsp &nbspServices &nbsp &nbspPublication &nbsp &nbspContact Us</font></DIV>' + ;
    '<DIV name="text_2" id="text_2" style="position:absolute; top:120px; left:570px; width:600px; height:25px"><font size="5" color="white">Welcome to <strong><i>Philippine Clearing House Corporation</i></strong></font></DIV>' + ;
    '<DIV name="text_3" id="text_3" style="position:absolute; top:160px; left:600px; width:450px; height:25px"><font size="3" color="white">Trusted as a neutral service.</font></DIV>' + ;
    '<DIV name="text_9" id="text_9" style="position:absolute; top:350px; left:101px; width:600px; height:25px"><strong>Welcome.</DIV>' + ;
    '<DIV class="roundcorner" name="box_services" id="box_services" style="position:absolute; top:655px; left:101px; width:500px; height:70px">' + ;
    '</DIV>' + ;
    '<DIV name="text_10" id="text_10" style="position:absolute; top:670px; left:115px; width:500px; height:70px"><font size="5" color="#304B56">Services</font></DIV>' + ;
    '<img id="pchc_logo_3" src="/img/sidebar-top.jpg" alt="pchc_logo_3" style = "position: absolute; top: 345px; left: 800px"/>' + ;
    '<DIV class="roundcorner" name="box_vmenu" id="box_vmenu" style="position:absolute; top:455px; left:800px; width:220px; height:180px">' + ;
    '</DIV>' + ;
    '<DIV name="text_2" id="text_2" style="position:absolute; top:470px; left:820px; width:350px; height:25px">Publications Search</DIV>' + ;
    '<DIV name="text_3" id="text_3" style="position:absolute; top:495px; left:820px; width:350px; height:25px">Option 1</DIV>' + ;
    '<DIV name="text_4" id="text_4" style="position:absolute; top:520px; left:820px; width:350px; height:25px">Option 2</DIV>' + ;
    '<DIV name="text_5" id="text_5" style="position:absolute; top:545px; left:820px; width:350px; height:25px">Option 3</DIV>' + ;
    '<DIV name="text_6" id="text_6" style="position:absolute; top:570px; left:820px; width:350px; height:25px">Option 4</DIV>' + ;
    '<DIV name="text_7" id="text_7" style="position:absolute; top:595px; left:820px; width:350px; height:25px">Option 5</DIV>' + ;
    '<DIV name="text_8" id="text_8" style="position:absolute; top:620px; left:820px; width:350px; height:25px">Option 6</DIV>' + ;
    '<img id="institution_logo" src="/img/institution-logo.jpg" alt="institution_logo" style = "position: absolute; top: 800px; left: 150px"/>' + ;
    '<DIV name="text_999" id="text_999" style="position:absolute; top:900px; left:372px; width:750px; height:25px"><font size="1">Powered by Harbour Project</font></DIV>' + ;
    hb_OSNewLine() + ;
    '<form name="LogInForm" id="LogInForm" action="www.yahoo.com" method="POST">' + ;
    '<input type="hidden" name="request" id="request" value="login" />' + ;
    '<DIV name="l_user_name" id="l_user_name" style="font-size:12px; position:absolute; top:43px; left:675px; width:65px; height:25px">User Name</DIV>' + ;
    '<input style="font-size:12px; position:absolute; top: 40px; left: 735px; width:100px" type="text" maxlength="50" name="username" id="username" size="15" value="" tabindex="1"/>' + ;
    '<DIV name="l_password" id="l_password" style="font-size:12px; position:absolute; top:43px; left:857px; width:100px; height:25px">Password</DIV>' + ;
    '<input type="password" style = "font-size:12px; position:absolute; top:40px; left: 910px; width:100px" maxlength="50" name="password" id="password" size="15" value="" tabindex="1" />' + ;
    '<input type = "submit" value="Log In" style = "font-size:12px; position:absolute; top:39px; left: 1025px; width:70px"/>' + ;
    '</form> ' + ;
    '<DIV name="l_reg_login" id="l_reg_login" style="font-size:12px; position:absolute; top:67px; left:800px; width:300px; height:25px"><a href="http://www.yahoo.com">Register </a> &nbsp &nbsp &nbsp|&nbsp &nbsp &nbsp <a href="http://wwww.yahoo.com">Forgot Password?</a></DIV>' + ;
    hb_OSNewLine() + ;
    '</body>' + ;
    '</html>'
   
    outstd( b )

    return
*end pagedbg

Daniele Campagna

unread,
Feb 18, 2014, 12:34:03 PM2/18/14
to harbou...@googlegroups.com
Il 18/02/2014 10:55, clipper6 ha scritto:
I tried hand coding the html tag instead of generating this on the fly but I still get the same error. I simply called pagedbg(). It loads okay the first time but when i click Home or any link for that matter I get a server error. See code below:

<snip>
I suppose you compiled -gtcgi of course.
Probably somewhere your program crashes with an error, and tries to write  to screen the error message.
Create an error manager that writes to stdout instead.
Time ago I posted the source, but IIRC it was in xHarbour newsgroup...
You can create a #command cgiout [<xList,...];
=>
([OutStd(<xList>),] OutStd hb_eol()

and use it to output error messages:
function myerr(e,bHandler)
...
cgiout ""
cgiout "Content-type: text/html"
cgiout ""
cgiout ""
cgiout "<html><body>"
cgiout "Error!"
if e:gencode== (etc. etc.)
....(explain the error...)
cgiout "</body></html>
return .f.

And use the myerr function: olderrorblock:=errorblock({|e|myerr(e,olderrorblock)})
HTH
Dan


clipper6

unread,
Feb 18, 2014, 8:33:34 PM2/18/14
to harbou...@googlegroups.com, cyber...@tiscalinet.it
I did as you advised but the error handler is working find but I don't think that it's a HB error. I think it has something to do with how/when the page rendered or displayed on the browser. I accidentally pasted pagedbg() before case request_method == "POST" and all the link worked except that at the top left this is printed "Content-type: text/html". Any CGI/HTML expert out there please help.



#include "hbclass.ch"

procedure Main()
    local request_method := "", b := ""
    local HTML := XCGI():New()
   
    request_method := Upper( HTML:REQUEST_METHOD )
       
    do case
    case request_method == "GET"
        if HTML:QUERY_STRING == ""
       
            pagedbg()

           
        elseif HTML:QUERY_STRING == "request=about"
           
            pagedbg()
           
        end if
       
       pagedbg() // accidentally pasted it here!!!!


    case request_method == "POST"   
   
    endcase
   
    return
*end Main   

Domenico D'Oria

unread,
Feb 19, 2014, 5:55:21 AM2/19/14
to harbou...@googlegroups.com, cyber...@tiscalinet.it
Hi Clipper6

first i'm not a cgi expert but in these day's i have the same problem.

i'm trying to explain where could be the issue.

my configuration :

Windows Vista business

LightTPD web server

HMGWEB alpha 8 by Roberto Lopez, i'm porting my alpha application from alpha 7 version

Roberto changes the session id procedure where he open some files with this command:

USE ../../data/users.dbf

before this change all works

after i have 500 internal server error

looking on LightTPD server windows and it show the blocking error, it could not find the pathname of the file, so probably in your code or in your data there be something wrong.

i hope this can help you

regards

Domenico

marek.h...@interia.pl

unread,
Feb 19, 2014, 4:19:55 PM2/19/14
to harbou...@googlegroups.com



Od: "clipper6" <arl...@gmail.com>


Do: harbou...@googlegroups.com;
Wysłane: 2:33 Środa 2014-02-19
Temat: Re: [harbour-users] Re: CGI: End of script output before headers


I did as you advised but the error handler is working find but I don't think that it's a HB error. I think it has something to do with how/when the page rendered or displayed on the browser. I accidentally pasted pagedbg() before case request_method == "POST" and all the link worked except that at the top left this is printed "Content-type: text/html". Any CGI/HTML expert out there please help.


Hi Clipper6

500 error are generated form web serwer, not in browser. What is your web serwer ? What return yuor code, pls check in error log file.

Regards,

Marek Horodyski


clipper6

unread,
Feb 19, 2014, 7:50:46 PM2/19/14
to harbou...@googlegroups.com
Thanks everyone for your reply I followed everyone's advise and was able to trace the cause of my problem. The error occurred since it had an IF condition that was NOT handled properly. By adding an ELSE I was able to catch the problem. I'm new to CGI and I am pressed for deadline with what I'm working now so I'm very panicky. So I panic a lot. The next issue I have is how to upload a PDF file. I hope someone could HELP me on this. Regards.

clipper6

unread,
Feb 19, 2014, 7:52:56 PM2/19/14
to harbou...@googlegroups.com
I using MS Windows XP/XAMPP on vmware. My workstation is running on Windows 8.


On Tuesday, February 18, 2014 5:14:53 PM UTC+8, clipper6 wrote:
Reply all
Reply to author
Forward
0 new messages