xampp for executing cgi application

Problems with the Windows version of XAMPP, questions, comments, and anything related.

xampp for executing cgi application

Postby wesleywj2 » 04. January 2004 07:57

hello there,

i'm a newbie for using apachefriends, i'm currently learning cgi. The problem I'm having is i'm unable to execute the cgi script. Sorry for asking bloody simple question, i'm not really smart with those server script procedure. I've noticed there is a folder under xampp call cgi-bin, i've tried to execute it under browser but came out with this error..
---------------------------
Bad request!
Your browser (or proxy) sent a request that this server could not understand.

If you think this is a server error, please contact the webmaster.

Error 400
localhost
1/4/2004 2:49:54 PM
Apache/2.0.48 (Win32) mod_perl/1.99_10 Perl/v5.8.0 mod_ssl/2.0.48 OpenSSL/0.9.7c PHP/4.3.4
---------------------------

i have no idea how the xampp links the file, so i hope anyone can give me a guide on how to execute a very simple cgi-script. A simple hello world html test will do..

thank you..
User avatar
wesleywj2
 
Posts: 3
Joined: 11. December 2003 11:49

Postby Kristian Marcroft » 04. January 2004 12:02

Hi,

could you please paste the First line of your cgi Script?

So long
KriS
User avatar
Kristian Marcroft
AF Moderator
 
Posts: 2962
Joined: 03. January 2003 12:08
Location: Diedorf

Postby wesleywj2 » 04. January 2004 21:33

hello kris,

thanks for the reply, the cgi application that i've written is using C program executed as .cgi app. There is a perltest.cgi inside /xampp/cgi-bin/, when I execute, it work just fine. The code for my C program cgi-app outlined below:

#include <stdio.h>

int main()
{
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<body>\n");
printf("<h1>Hello there!</h1>\n");
printf("</body>\n");
printf("</html>\n");
return 0;
}


I used DJGPP C compiler for this source code.
further reply will be much appreciated.. thank you :)
User avatar
wesleywj2
 
Posts: 3
Joined: 11. December 2003 11:49

Postby Kristian Marcroft » 04. January 2004 22:56

Hi,

how about adding a first line with:

#!C:/xampp/perl/bin/perl.exe

The cgi Script doesn't know where the Parser is...

So long
KriS
User avatar
Kristian Marcroft
AF Moderator
 
Posts: 2962
Joined: 03. January 2003 12:08
Location: Diedorf

it's a C program not a Perl script...

Postby chanio » 14. January 2004 20:24

:lol:
In fact, this cgi-bin dir only works with perl scripts: that is... .PM or .PL or .CGI.
You could also tell your server to execute more programs:
shell scripts, C files, JAVA files, etc. but this httpd.conf is only programmed to understand Perl scripts or PHP files. Not too much but enough for the most of us.
Try this code: (save the file as hello.pl).-.-.-.-.-.-.-.-.-.---.---
#!/xampp/perl/bin/perl.exe -w
# [ hello.pl ] show that it is working
# try it writing http://localhost/cgi-bin/hello.pl at your browser's address bar.
use strict;
print ("Content-type: text/html\n\n <html><head><title>HelloWorld</title></head><body>");
my ($values);
foreach (sort(keys(%ENV)))
{
$values.="<tr><td>$_</td><td>$ENV{$_}</td></tr>\n";
}
print <<EOF;
<h1>Hello World</h1>
<table><tr><th>Env.Variable</th><th>Values</th>\n$values</table>
<tr><p>These are the server's environment variables. Hope this helps to start all: see >perldoc perldoc as a starting point</p>
</body></html>
EOF

exit 0;
.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.--.-.-.-.-.-----
Hope it helps!
Gallactic Firewall
User avatar
chanio
 
Posts: 72
Joined: 18. March 2003 22:05
Location: Argentina

Gratitude

Postby wesleywj2 » 15. January 2004 20:25

hello kris & chanio,

thanks so musch for the reply, initially i thought using C language is the only way to execute CGI app under Apache environment, after much reading from other sources only to found out perl is the only recommended language to execute CGi. Most of the article explain mainly about perl and C language offered a very complex algorithm in order to maintain the CGI session. I think it would be better to use perl instead of C language. By the way, thanks again for the reply..i now know which language to pursue. thanks for the sample code as well :D .

regards,
from wesleywj2
User avatar
wesleywj2
 
Posts: 3
Joined: 11. December 2003 11:49


Return to XAMPP for Windows

Who is online

Users browsing this forum: mark.mcdonald and 59 guests