libcgi_cgi - Man Page


CGI manipulation ā€”


formvars * cgi_process_form ()
Process HTML form or URL data.
void cgi_fatal (const char *msg)
Kills the application with a message.
int cgi_include (const char *filename)
Include static files.
void cgi_init_headers ()
Initialize HTML headers.
char * cgi_param_multiple (const char *name)
Return all values with the same name sent by a form.
void cgi_redirect (char *url)
Recirects to the specified url.
int cgi_init ()
Main cgi function.
void cgi_end ()
Performs cgi clean ups.
char * cgi_unescape_special_chars (char *str)
Transforms' URL special chars.
char * cgi_escape_special_chars (char *str)
Transforms' special characters into hexadecimal form ( %E1 ).
char * cgi_param (const char *var_name)
Gets the of HTML or URL variable indicated by 'name'.
void cgi_send_header (const char *header)
Sends a specific header.

Function Documentation

void cgi_end ()

Performs cgi clean ups.Provides some methods to clean memory or any other job that need to be done before the end of the application.

See also:


char* cgi_escape_special_chars (char * str)

Transforms' special characters into hexadecimal form ( %E1 ).Parameters:

str String to parse


The new string

See also:


void cgi_fatal (const char * msg)

Kills the application with a message.Writes msg and terminate


msg Message to send to the browser before killing

int cgi_include (const char * filename)

Include static files.Function used to include static data ( normaly html files ). File contents will never be processed. Note that I don't scan for any special character. The reason I did it is, if the you are using this library, you have a shell where you can compile the cgi program. And can do much more ;-)


filename Filename with full path to include


If an error occurs and libcgi_debug is true, then a warning message is showed.

See also:



int cgi_init ()

Main cgi function.Configures all (most?) we need to get cgi library working correctly. It MUST be called before any other cgi function.

See also:

cgi_end, cgi_process_form, cgi_init_headers

void cgi_init_headers ()

Initialize HTML headers.You need to call this function before that any content is send to the brosert, otherwise you'll get an error (Error 500).

See also:


char* cgi_param (const char * var_name)

Gets the of HTML or URL variable indicated by 'name'.Parameters:

name Form Variable name

See also:

cgi_param_multiple, cgi_process_form, cgi_init

 // ...
 char *contents;
 contents = cgi_param('foo');
 // ...

char* cgi_param_multiple (const char * name)

Return all values with the same name sent by a form.Parameters:

name Form variable name


Form variable contents

See also:


Example: For example, if in your HTML you have something like

 'What do you like??'

  Computers : <input type='checkbox' name='like' value='computers'><br>
  Internet : <input type='checkbox' name='like' value='net'><br>
  games : <input type='checkbox' name='like' 'value='games''><br>

 then, to retrieve all values, you can make a code like

 // ...
 char *data;
 \ ...
 while ((data = cgi_param_multiple('like')) != NULL)
 \ ...

formvars* cgi_process_form ()

Process HTML form or URL data.Used to retrieve GET or POST data. It handles automaticaly the correct REQUEST_METHOD, so you don't need to afraid about it.


Returns the contents of URL or FORM into a formvars variable, or NULL if FALSE. Most of time, you don't need any variable to store the form data, because is used an internal variable to manipulate the contents.

See also:

cgi_init, cgi_init_headers

void cgi_redirect (char * url)

Recirects to the specified url.Remember that you cannot send any header before this function, or it will not work. Note:
LibCGI does not implement RFC 2396 to make the lib simple and quick. You should be sure to pass a correct URI to this function.


url url to redirect the browser


void cgi_send_header (const char * header)

Sends a specific header.Sends a specific HTTP header. You won't need to add '\n\n' chars.


header HTTP header to send, without new line characteres



See also:


char* cgi_unescape_special_chars (char * str)

Transforms' URL special chars.Search for special chars ( like %E1 ) in str, converting them to the ascii character correspondent.


str String containing data to parse


The new string

See also:



13 Mar 2003 LibCGI