PDA

View Full Version : Downloads instead of Executing...


dniwebdesign
01-08-2004, 04:35 AM
I am trying to set up some scripts on a website. There was a CGI bin so I believe that CGI is available. However whenever you try to view a script it tries to download it instead of viewing it or executing it. How can I fix this or do I need to contact the admin of the server?

Example at http://www.usask.ca/goldenkey/cgi-bin/env.cgi

YUPAPA
01-08-2004, 06:42 AM
Hi~

1) It could be you dun have the mimetypes for .cgi files
This can be solved by putting the code below in a .htaccess file

AddType text/html .cgi


2) Your script could be printing a wrong header
This will print the output of the script as HTML

print "Content-Type: text/html\n\n";

Feyd
01-08-2004, 07:58 PM
Actually, adding a type of text/html for a cgi script is going to make the results print out as standard text (HTML) as opposed to executing the script.

You would need to use

AddType application/x-httpd-cgi .cgi
or (depending on your server config)
AddType cgi-script .cgi
or
AddType cgi-script .cgi .pl

Also, make sure that your scripts have execute permissions (644 or 755, via CHMOD)

Though Yupapa is right about the content-type, it is a mistake many beginners make to not specify that content-type if a script is intended to result in printing data back to the browser...

dniwebdesign
01-08-2004, 08:59 PM
Okay nevermind... I found the problem...

Instead of executing the script through www.domain.com/~user/cgi-bin/script.cgi

it is www.domain.com/cgi-bin/cgi-wrap/~user/cgi-bin/script.cgi

Why I don't know but I guess that is how the University has it set up. Thanks anyways.

Feyd
01-09-2004, 01:10 AM
Ew....it is running through a wrapper. Just basically allows different onwership for things, despite the actual file owner (the user ID it was uploaded or created under, as opposed to the id it is being executed as). Not surprising, in a uni environment...you just kind of have to deal with it, although you would think they might do some conf or redirects to make the URL for it shorter, but it isn't a large issue.