OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 4:30 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 12 posts ] 
Author Message
 Post subject: cgi
PostPosted: Mon Jan 27, 2003 6:31 pm 
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?


Top
  
 
 Post subject: Re:cgi
PostPosted: Mon Jan 27, 2003 7:24 pm 
Well to print html in perl you would do this:

Code:
print "HTML HERE/TEXT HERE";


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.


Top
  
 
 Post subject: Re:cgi
PostPosted: Mon Jan 27, 2003 7:29 pm 
Here is some code to get the GET data from the url:

Code:
@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?


Top
  
 
 Post subject: Re:cgi
PostPosted: Mon Jan 27, 2003 8:01 pm 
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.


Top
  
 
 Post subject: Re:cgi
PostPosted: Tue Jan 28, 2003 2:58 am 
It's easy; just write it in C. Write your output to stdout. HTTP server variables are available through the environment (getenv).


Top
  
 
 Post subject: Re:cgi
PostPosted: Tue Jan 28, 2003 1:25 pm 
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?


Top
  
 
 Post subject: Re:cgi
PostPosted: Tue Jan 28, 2003 1:45 pm 
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.
Quote:
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)


Top
  
 
 Post subject: Re:cgi
PostPosted: Tue Jan 28, 2003 5:00 pm 
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?


Top
  
 
 Post subject: Re:cgi
PostPosted: Wed Jan 29, 2003 2:32 pm 
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.


Top
  
 
 Post subject: Re:cgi
PostPosted: Wed Jan 29, 2003 8:45 pm 
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?


Top
  
 
 Post subject: Re:cgi
PostPosted: Mon Feb 03, 2003 7:30 pm 
any help?


Top
  
 
 Post subject: Re:cgi
PostPosted: Mon Feb 03, 2003 8:38 pm 
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.


Top
  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 12 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 95 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group