G Web Server Examples

Password CGI

When an HTTP server successfully fulfills a request, it returns an status code 200 indicating success. A CGI can override this default status code by returning a

Status: xxx

line in the header parameter. The CGI can also specify other header lines that should be returned with the HTTP reply.

When a CGI want's to authenticate a user, it can check the REMOTE_USER and REMOTE_IDENT environmental variables. If they don't exist or are not acceptable, the CGI can return a 401 reply, indicating that a password is required. The full header should be:

Status: 401 error message
WWW-Authenticate: Basic realm="name"

The first line tells the server to return a 401 reply code.
The second line specifies the authentication method (currently only Basic is supported) and the text with which the user should be prompted for a password.



The following CGI requires a valid user name and password and if it is satisfied, it returns an HTML document consisting of the user name and password. The CGI accepts any user whose user name is in capital letters and whose password is the same as the user name in lower case letters.

Example:    User JOHN
  Password john

/cgi-bin/examples/password.vi


© National Instruments