Page 1 of 1
cgi
Posted: Mon Jan 27, 2003 6:31 pm
by elias
im making an online game that is made in C. now does teh program have to generate teh html itself? and also, hwo do i read in the info submitted from teh browser?
Re:cgi
Posted: Mon Jan 27, 2003 7:24 pm
by AGI1122
Well to print html in perl you would do this:
as for getting info from the browser there are 2 main info types you need to collect, GET and POST data.
POST data is sent by clicking on a button in the html page.
GET is a variable in the url of your browser.
And you can't make it in C. cgi programs are text documents that are run by the perl interpreter. So you can use notepad, or some text editor or, a perl editor to make your perl code.
Also you need to be aware that the first line of your main perl script MUST contain the proper shebang line. The shebang line is the path to your perl interpreter on your webserver.
Anyway, if you need some help with this just ask.
Re:cgi
Posted: Mon Jan 27, 2003 7:29 pm
by AGI1122
Here is some code to get the GET data from the url:
Code: Select all
@query_strings = split('[;&]',$QUERY_STRING);
foreach $tmp (@query_strings) {
???($key,$value) = split(/=/,$tmp);
???$$key = $value;
}
Now for instance, if somebody typed index.cgi?action=test
Then in your script, $action would be set to equal "test".
Understand how that works? And you can seperate multiple variables in the url by putting a & or a ; between them. Like this:
index.cgi?action=test;name=Chris
or
index.cgi?action=test&name=Chris
This will make it so $action is set to "test" and $name is set to "Chris".
Anyway does this help you some?
Re:cgi
Posted: Mon Jan 27, 2003 8:01 pm
by ark
actually, a CGI program can be written in C, but I don't have any experience with it so I can't tell you how it's done.
Re:cgi
Posted: Tue Jan 28, 2003 2:58 am
by Tim
It's easy; just write it in C. Write your output to stdout. HTTP server variables are available through the environment (getenv).
Re:cgi
Posted: Tue Jan 28, 2003 1:25 pm
by elias
what do you mean by enviromental variables? cant i just open up an input stream with the internet connection, and since the browsers on the other side, wat i read in will be what is sends. cant i do that?
Re:cgi
Posted: Tue Jan 28, 2003 1:45 pm
by Tim
elias wrote:what do you mean by enviromental variables?
I mean an environment variable.
All mainstream operating systems have them. If you're running Windows, bring up a command prompt and type SET.
cant i just open up an input stream with the internet connection, and since the browsers on the other side, wat i read in will be what is sends. cant i do that?
I'm not sure what you're talking about here.
A CGI program works as follows:
- The HTTP server gets a request for a file that it knows is executable (the CGI program)
- The server sets up environment variables for things like the original HTTP request string and the headers that the browser sends
- The server starts the CGI program and redirects its standard output stream (stdout in, std::cout in C++) to the connection it has with the user's browser
- The CGI program does what it needs to and emits headers and HTML (or headers and some other file, depending on the Content-Type header it emits)
Re:cgi
Posted: Tue Jan 28, 2003 5:00 pm
by elias
well then i guess its not a cgi. i guess its just a server. so my server only has to set up an input stream on the port, and itll read whatever the browser sends? i think i understand. but this also means that the prog will generate teh html to spit out, depending on what it reads in. thats not a prob. but another question, how do i set it up, so that tht html gives a link, that when clicked, goes into a message board. will i have to create a pseudo message board through html? just one that accepts posts, and adds them?
Re:cgi
Posted: Wed Jan 29, 2003 2:32 pm
by Tim
It sounds like a CGI program is what you want, unless you feel like writing your own HTTP server from scratch.
I suggest you read the documentation of whatever HTTP server you're using. If you don't run your own HTTP server (e.g. you're using webspace provided by someone else), you need to talk to your provider.
Re:cgi
Posted: Wed Jan 29, 2003 8:45 pm
by elias
i didnt even know i needed to run an HTTP server. im new ot web programming. so through a HTTP server, i can also run a message board, so that from the code my cgi spits out, users can connect to? ie, the cgi sends out a link, so that when a logged in user clicks on it, they will be logged into the message baord?
Re:cgi
Posted: Mon Feb 03, 2003 7:30 pm
by elias
any help?
Re:cgi
Posted: Mon Feb 03, 2003 8:38 pm
by AGI1122
Yes that is correct you do need to run it through a HTTP server. And yes you can make it so your code spits out a link to login... although you have to build the login functions and such.
Of course you can always download a cgi message board... although most cgi message boards are flat file and alot of hosts disallow flat file message boards and will drop you from being hosted if you use one.
I do recommend YaBB(flatfile) and IkonBoard(MySQL) those 2 cgi message boards are the best in my opinion.