Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: nsyslaw at acs dot ncsu dot edu
Subject: Re: Hi All (WWW/CGI scripts)
Date: Dec 5 1995 6:36PM

I don't have all the information for a complete answer on this, but perhaps
this will help.  (Aren't NCSA's messages wonderful?)  

Sybperl 4.036 has a generic message handler which will return some of the 
messages returned from the sql server.  If the NCSA server (and Netscape
Commerce/Communications, and probably Apache) see this output from the script,
before seeing the content-type line, they'll barf with the error message you're
getting.  After the snippet of the original message, I'll sprinkle a couple of
comments into the script which may provide a few pointers.

Earlier, Skye Hauptman ( wrote:
> I am encountering a bizarre problem and I was hoping someone out there would 
> know a workaround (if you're in the New York City area, drinks are on me, if 
> you're not come into town and we'll do the same)
> I am integrating sybperl with a web/cgi script and it runs fine on the command 
> line, but dies with 'ERROR 500, malformed header'. I call &dbuse and &dblogin 
> prior to printing the cgi header, and I think the problem rest in the system 
> call (or maybe how my sybperl is situated in the web directory (it is included 
> in the server root path)
> [snip]
> ****************************************
> #!/home/hauptman/sybperl
> [require's, and form input stuff and username and password deleted]
> $dbproc = &dblogin ($user,$password);

Here I'm beginning to see something that may be of use.  I don't know how your
web server is set up, but if it's like ours it's running as a restricted user
(either nobody, or some other specifically for the purpose).  As such, it may
not have many environment variables set up, such as your shell will.  In the
above line, the variable DSQUERY will have to be set, or it won't know what 
server to connect to.  Further below I'll give some examples of forcing the 
environment variables from within the script.

> &dbuse("$database");

Where is $database defined?  If it's not, this will generate a message too.
(I believe).

Those are just two potential sources of text output to the server before 
getting the following type line: (which generates malformed header errors)

> [snip]
> print("Content-type: text/html\n\n");

Lastly, move this line up to the top of the script.  That way if the sybase message
handler generates messages you'll see them, instead of getting 500 server error
(malformed header).  It makes debugging a much easier process.

Also, you may want to explicitly define some variables in the script.  For example
to set the SYBASE and DSQUERY variables I would use something like the following:

$ENV{'SYBASE'} = "/usr/local/sybase";	# force sybase environment variable.
$ENV{'DSQUERY'} = "myserver";		# force dsquery environment variable.

Hope this helps!
 Lou Williams (     | aka:   KE4ARM  
 Unix Systems Programmer                 | Phone: (919) 515-2794  
 NCSU Administrative Computing Services  | FAX:   (919) 515-3787 
"It is good to have friends, is it not Mr. Garibaldi?"
		   - Londo Mollari; Babylon 5: Acts of Sacrifice