-
php and C++
with my version of OmniHTTPd, in the cgi-bin, theres a couple of programs, which in the readme, says they're written in C++.
the program generates an image of the counter, with the current number of hits. i attached the readme, incase you dont know what i mean
how do you write CGI-Executables in C++?
the person said he has the full-source on his page, but the page was down.
also, my other question
http://www.vbforums.com/showthread.p...hreadid=129496
thanks
-nabeel
-
1 Attachment(s)
just adding the attachment
-
Just write "Content-type: text/html\n\n" to STANDARD OUTPUT and then your HTML data.
Code:
#include <stdio.h>
#include <stdlib.h>
main() {
char *chRM;
char *chQS;
chRM = getenv("HTTP_USER_AGENT");
//check for NULL or we'll get at error with printf
if (chRM == NULL) {
chRM = "NONE";
}
chQS = getenv("QUERY_STRING");
if (chQS == NULL) {
chQS = "NONE";
}
printf("Content-type: text/html\n\n");
printf("<html>\n");
printf("<head><title>CGI Test</title></head>\n");
printf("<body>\n");
printf("<p>Hello World!\n");
printf("<br><b>HTTP_USER_AGENT:</b> ");
printf(chRM);
printf("<br><b>QUERY_STRING:</b> ");
printf(chQS);
printf("</p>\n");
printf("</body>\n");
printf("</html>\n");
return 0;
}
-
-
1 Attachment(s)
This is quite old so it's not the greatest code around - I can see some obvious optimisations it can have (not to mention some things which are evil enough to demand a rewrite), but I don't really need it anymore so I'm sure you can manage it nicely :D
So Ked, no jumping down my throat about any of it, k? :p
-
-
spreading evil code around again parksie? :D where's the headerfile`?
*prepares to write a load of comments* j/k ;)
-
yah, u forgot the header file
so, i just add it to my project and since its a class, i just declare and use it?
cool-o.
optimizations: err i have no clue. but that's ok :) im horrible at C++
how would i process a parameter that is passed? lets say
cgiexetext.exe?URL=http://www.hotmail.com
just check for it through the void main(int argc, char *argv[]) way? like retrive it then parse it?
thx guys :)
-
1 Attachment(s)
Sorry I couldn't get onto VBW last night very well, and I thought it had attached it but obviously not (you might notice that this was one of my last posts yesterday).
Anyway, I didn't forget - see my post above :p
Code:
CLibCGI CGI;
string keyword;
CGI.Setup();
keyword = CGI.GetValueFromName("keyword");
:)
I admit, something like this would have been better:
Code:
CLibCGI CGI;
keyword = CGI["keyword"];
But remember, I wrote this in Feb 2000 so it's getting VERY old now :D
-
heh. cool thanks. so i would do
Code:
CLibCGI CGI;
string URL;
CGI.Setup();
URL = CGI.GetValueFromName("URL");
and then from there i can do what i want/need?
thanks for the help! :)
-
ok i tried it like you said, and it gives an error, and it wants to send an error report to microsoft. (running win xp)
but, when i take out the CGILib stuff, it works fine, it outputs.
Code:
//#include "libcgi.cpp"
#include "libcgi.h"
void main(int argc, char *argv[]){
CLibCGI cgi;
string URL;
cgi.Setup();
printf("Content-type: text/html\n\n");
printf("<html><head><title>Forwarding...</title></head>\n\n");
URL = cgi.GetValueFromName("site");
if(URL.length == 0){
printf("<body>");
printf("No URL was specified<br>\n\n");
printf("</body></html>");
}
else{
printf("<script>window.location = %c%s%c;</script>\n\n",39,URL,39);
printf("</body></html>");
}
}
thanks
-
Don't include the .cpp file - you compile that separately and link it in.
-