Checking if a session existsΒΆ
get_web_session() |
Check if a session exists |
SYNTAX
get_web_session(session_file_id)
If a session exists, read the session record from the specified session file, and perform a security check on the IP address of the client and the authorised user name. These are contained in the fields session_file_id.IPAddress and session_file_id.AuthorisedUser respectively.
The function updates the field session_file_id.Expires, which contains the session expiry time, and writes the session record back. The new expiry time is calculated by adding the time-out period to the current time. The expiry time is not updated unless this function is called.
The program knows the session ID for this client, and therefore which record to read from the session file, because it was sent the ID either as a web parameter or as a cookie, with the name SC_SESSION_ID. See create_session().
The function returns 0 (OK) or a negative value to indicate an error. The possible errors, defined in http.h with the prefix WWW_ERR_, are:
PARAMETER; SESSION_FILE_CLOSED; NO_CLIENT_SESSION; EXPIRED_SESSION; NO_FIELDNAME_FLD; BAD_IPADDRESS; BAD_AUTH_USER; WITH_SESSION_FILE
EXAMPLE
!ofile session session update
!define SREP_NAME "/cgi-bin/nph-srep.exe"
if (get_web_session(session) < 0) {
web_redirect(SREP_NAME + "?login")
exit
}
RELATED TOPICS |