CHttpServer::SetClientVariable Method  
 
BOOL HttpSetClientVariable(
  UINT nClientId,  
  LPCTSTR lpszName,  
  LPCTSTR lpszValue  
);

Create or change the value of a CGI environment variable for the specified client.

Parameters

nClientId
An unsigned integer which uniquely identifies the client session.
lpszName
A null-terminated string that specifies the name of the environment variable that should be created or modified. Environment variables are not case-sensitive and should not include the equal sign which acts as a delimiter that separates the variable name from its value. This parameter cannot be a NULL pointer or an empty string.
lpszValue
A null-terminated string that specifies the new value of the environment variable. If this parameter is a NULL pointer or an empty string, it has the same effect as deleting the variable from the environment block for the client session.

Return Value

If the method succeeds, the return value is non-zero. If the client ID does not specify a valid client session, the method will return zero. If the method fails, the GetLastError method will return more information about the last error that has occurred.

Remarks

The SetClientVariable method will change the value of a environment variable for the specified client session. If the lpszName value matches an existing variable, its value will be replaced. If the variable is not defined, then a new variable will be created with the given value. The value of an environment variable can be obtained using the GetClientVariable method.

The server will automatically create a number of different environment variables that will be passed to a program or script executed by the server. These variables are defined in RFC 3875 as part of the Common Gateway Interface (CGI) 1.1 specification. The following variables are defined by the server and should not be modified directly by the application:

Variable Name Description
AUTH_TYPE The authorization scheme used by the server to authenticate the client session
CONTENT_LENGTH The length of the request data provided by the client
CONTENT_TYPE The MIME type that identifies the type of content provided by the client
DOCUMENT_ROOT The full path to the local document root directory on the server
GATEWAY_INTERFACE The version of the Common Gateway Interface that is being used by the server
PATH_INFO The resource or sub-resource that is to be returned by the program or script
PATH_TRANSLATED The path information mapped to the server root document directory structure
QUERY_STRING The URL encoded query parameters passed to the program or script
REMOTE_ADDR The network address of the client sending the request to the server
REMOTE_HOST The same value as the REMOTE_ADDR variable
REMOTE_USER The username specified as part of the authentication credentials provided by the client
REQUEST_METHOD The method used by the client to request the resource
REQUEST_URI The URI for the script provided by the client
SCRIPT_FILENAME The full path to the program or script on the server
SCRIPT_NAME The path to the program or script specified by the client
SERVER_NAME The hostname or IP address of the server that the client connected to
SERVER_PORT The port number that the client used to connect to the server
SERVER_PORT_SECURE This variable has a value of "1" if the client connection to the server is secure
SERVER_PROTOCOL The version of the server protocol used
SERVER_SOFTWARE The server identity string which specifies the application name and version

In addition to the environment variables listed, the server will also create variables that are prefixed with "HTTP_" that are set to the value of request headers that are not otherwise defined. For example, the HTTP_USER_AGENT variable will be set to the value of the User-Agent header provided by the client as part of the request.

Calling the SetClientVariable method within an OnExecute event handler will have no effect because it occurs after the CGI program or script has completed execution. To create or modify environment variables for the client session, it should be done within an OnCommand event handler.

This method will not change the environment block for the server process. Each client session is allocated its own private environment block which is inherited by the CGI program. When the client session terminates, the memory allocated for its environment is released.

Requirements

Minimum Desktop Platform: Windows 7 Service Pack 1
Minimum Server Platform: Windows Server 2008 R2 Service Pack 1
Header File: cstools12.h
Import Library: cshtsv12.lib
Unicode: Implemented as Unicode and ANSI versions

See Also