c++ cgi?

Status
Not open for further replies.
i had some problem when i worte a simple win32 app, that prints something to a cmd window.., i excecuted it over iss, the exectuion when fine...but it retrund some wired things...
"invalid http header(something like that) something....
heres the code..well stript down...
main(bla bla bla)
{
printf("something");
}

what is the corect way of doing this????
 

petrov

Ars Tribunus Militum
2,714
Originally posted by andy4285:
do you have anyiedeas how to prevent buffor overflow hacks??...i think that would be the only real problem...this is only for

use a safe language. if you don't like perl, then write it in python, or scheme, or java, or any other language with buffer overflows. Writing a non-trivial C++ CGI script is horrible idea as input validation is going to be really difficult.

administration stuff, so if i protect the directory, do i need to worry about security???

ummm. yes. Guessing passwords over the wire is pretty easy. Sniffing passwords is pretty easy. Just because you think only administrators can login, that doesn't mean that only administrators will login. Security isn't a boolean, you always want to have a defense in depth for any kind of production data. The only case in which you get no extra security by writing your code correctly is if every single last one of your users has the exact same write privileges as the web daemon, and your code is never adapted or changed to break this design assumption.

in short, C++ is a great language, I use it myself occasionally. but don't write network server programs in it if you can at all help it.

--sam
 
I'm a huge fan of C# for ASP pages, but I will admit that PHP is still probably the best HTML scripting language EVAR. Consider it for the following reasons (any one of which is a reason to drop C++):

  • It's free
  • Documentation is immense and accesible
  • It was made for this kind of stuff
  • It's got great OOB database connectivity
  • Form data and query string parameters are pratically trivial
  • It's easy to find PHP hosts, and easy to set one up yourself
  • PHP's syntax is C-like, which makes for an easy transition for most people


I think a lot of people will agree on this one.

C++ for cgi? ::shudder:: But whatever floats it...

[edit] Of course, PHP is for scripting, not pure CGI, but in many cases you can just alter your way of thinking a little bit and use it instead. Perl is more common for straight CGI, but I doubt there will be many instances where a well written scripted page won't do what you want.
 

wb

Ars Legatus Legionis
25,208
Subscriptor
It's a better idea than writing them in C. And anything is better than writing them in (ugh) perl. Even brainfuck.

No bias there, I see.

Perl happens to be very good at CGI, and it's also platform-neutral. In fact, the reason I learned it in the first place many years ago was to run CGI that happened to be running on a distributed file system (AFS) that ran on several different platforms. I found to my dismay that after implementing some CGI code in C, I got nothing but core dumps trying to access my programs via the WWW. I had no choice at the time but to write the code using a scripting language (Java was not invented yet) and perl was the obvious choice. At the time I had to write everything from scratch, and I still spent less time learning perl and writing all of the necessary code than I did writing the C code. Nowadays it's 10 times easier, as there's a group of perl modules called CGI::(module) that makes developing just about anything to do with CGI extremely easy to implement.
 
Originally posted by PreciousRoy:
I'm a huge fan of C# for ASP pages, but I will admit that PHP is still probably the best HTML scripting language _EVAR_. Consider it for the following reasons (any one of which is a reason to drop C++):
+ It's free
+ Documentation is immense and accesible
Ditto C++, perl, etc....

+ It was made for this kind of stuff
+ It's got great OOB database connectivity
No, it hasn't. "Great" database connectivity would not have a different set of functions for all the different database engines you might want to connect to.
 

petrov

Ars Tribunus Militum
2,714
the browser converts spaces in the URL to %20, but it should convert spaces in the form data into '+'. other non-alphabetic characters get converted into %xx where xx is the ascii code for the character. the various form fields get linked together with ampersands. all of this data gets bundled in the URL if your form input is set to GET, otherwise if it's set to POST, it gets passed into the CGI on stdin.

to parse this (and correctly handle malicious input) in C++ is going to be a pain in the ass, but that's not my problem. :)

--sam
 
Status
Not open for further replies.