---
name: "libcgi_session"
section: "3"
platform: "linux"
package: "libcgi-dev"
version: "1.0-6"
release: "Debian 5.0 (Lenny)"
platforms: ["linux"]
url: "https://new.carta.tech/libcgi_session"
---

# libcgi\_session(3)

## NAME

Session Handling -

## Detailed Description

One of the most diferencials of LibCGI is its support to sessions, a mechanism that permits the application to keep variables trough the user's session, when he is visiting your website.

### Functions

int **cgi\_session\_destroy** ()\
 *Destroys the session.* char \* **cgi\_session\_var** (const char \*var\_name)\
 *Gets session variable's value.* void **cgi\_session\_cookie\_name** (const char \*cookie\_name)\
 *Defines the name of the cookie that LibCGI will use to store session's ID.* void **cgi\_session\_save\_path** (const char \*path)\
 *Defines where session control files will be saved.* int **cgi\_session\_register\_var** (const char \*name, const char \*value)\
 *Register a variable in the current opened session.* int **cgi\_session\_alter\_var** (const char \*name, const char \*new\_value)\
 *Alter session variable value.* int **cgi\_session\_var\_exists** (const char \*name)\
 *Searches for determined session variable.* int **cgi\_session\_unregister\_var** (char \*name)\
 *Unregister some session variable.* int **cgi\_session\_start** ()\
 *Starts a new session.*

## Function Documentation

### int cgi\_session\_alter\_var (const char \* name, const char \* new\_value)

Alter session variable value.Change session variable 'name' value to data pointer by 'new\_value'

**Parameters:**

*name* Session variable name to change \
 *new\_value* New session variable value

**See also:**

**cgi\_session\_register\_var()**, **cgi\_session\_unregister\_var()**

### void cgi\_session\_cookie\_name (const char \* cookie\_name)

Defines the name of the cookie that LibCGI will use to store session's ID.This function works like **cgi\_session\_save\_path()**. This functionality let you to use different names for each site, but remember, you cannot use multiple session for the same application yet.

**Parameters:**

*cookie\_name* Name of the cookie to create

**See also:**

**cgi\_session\_save\_path()**

**Note:**

This function must be called before **cgi\_session\_start()**

### int cgi\_session\_destroy ()

Destroys the session.Destroys the current opened session, including all data. After session\_destroy() was called, is not more possible to use session functions before an another call to session\_start()

**Returns:**

1 if no errors, 0 if.

**See also:**

**cgi\_session\_start**

cgi\_session\_error\_message

### int cgi\_session\_register\_var (const char \* name, const char \* value)

Register a variable in the current opened session.Note that we are opening and closing the session file every time this function is called... ( I/O ^ 1000000 :-/ )

**Parameters:**

*name* Variable name \
 *value* Variable value

**See also:**

**cgi\_session\_alter\_var()**, **cgi\_session\_unregister\_var()**

### void cgi\_session\_save\_path (const char \* path)

Defines where session control files will be saved.If in the your CGI you don't make a call to **cgi\_session\_save\_path()**, LibCGI will use the default value, which is '/tmp/'. To see how to modify the value, see the following example. \
 Just note you need to add '/' at the end of the directory name

```
 // your_cgi.c
 // Set 'session_files' directory under your CGI directory as the path
 // which LibCGI will use to store session files.
 cgi_session_save_path('session_files/');
```

Note that using this form, LibCGI will search for 'session\_files' directory using relative path to your cgi application. For example, if your CGI script is located at /usr/local/httpd/web/your\_name/cgi-bin/ directory, and you use the above declaration, the files for the session will be stored at /usr/local/httpd/web/your\_name/cgi-bin/session\_files directory. Resuming, the path is relative to where your application resides. \

And remember, LibCGI **does** **not** create the directory for you.

**Parameters:**

*path* Path, relative or absolute

**See also:**

**cgi\_session\_cookie\_name**

**Note:**

This function must be called before **cgi\_session\_start()**

### int cgi\_session\_start ()

Starts a new session.This function is responsible for starting and creating a new session. It must be called before any other session function, and every time before any HTML header has sent.

**See also:**

session\_destroy()

### int cgi\_session\_unregister\_var (char \* name)

Unregister some session variable.**Parameters:**

*name* Session variable name to unregister

**See also:**

**cgi\_session\_var\_exists()**, **cgi\_session\_register\_var()**

### char\* cgi\_session\_var (const char \* var\_name)

Gets session variable's value.**Parameters:**

*name* Session variable name to get the value

**Returns:**

Variable contents if found, NULL if not.

**See also:**

**cgi\_session\_var\_exists()**

### int cgi\_session\_var\_exists (const char \* name)

Searches for determined session variable.**Parameters:**

*name* Session variable name to search

**Returns:**

1 if variable is registered, 0 if not

**See also:**

**cgi\_session\_var()**
