Home > Article > Backend Development > Summary of PHP session function processing, php session function_PHP tutorial
PHP session processing functions include: session_start, session_register, session_is_registered, session_unregister, Session_destroy, etc. I believe that everyone will have some understanding of the session function of PHP when learning the PHP language. The following editor will share with you a summary of the session functions of PHP.
When the client's cookies are disabled, it will automatically be passed through Query_String. There are a total of 10 PHP session processing functions. Let's introduce in detail several functions that will be used.
PHP processing session function 1. session_start
Function: Start a session or return an existing session.
Function prototype: boolean session_start(void);
Return value: Boolean value
Function description: This function has no parameters and the return value is true. It is best to put this function first, and there must be no output before it, otherwise an alarm will be issued, such as: Warning: Cannot send session cache limiter – headers already sent (output started at /usr/local/apache/htdocs/cga /member/1.php:2) in /usr/local/apache/htdocs/cga/member/1.php on line 3
PHP processing session function 2, session_register
Function: Register a new variable as a session variable
Function prototype: boolean session_register(string name);
Return value: Boolean value.
Function description: This function adds a variable to the current SESSION in the global variable. The parameter name is the name of the variable you want to add. If successful, it returns the logical value true. You can use the form $_SESSION[name] or $HTTP_SESSION_VARS[name] to get or assign a value.
PHP processing session function 3. session_is_registered
Function: Check whether the variable is registered as a session variable.
Function prototype: boobean session_is_registered(string name);
Return value: Boolean value
Function description: This function can check whether the specified variable has been registered in the current session. The parameter name is the name of the variable to be checked. If successful, the logical value true is returned.
PHP processing session function 4, session_unregister
Function: Delete registered variables.
Function prototype: boolean session_session_unregister(string name);
Return value: Boolean value
Function description: This function deletes variables in global variables in the current session. The parameter name is the name of the variable to be deleted, and returns true if successful.
PHP processing session function 5, session_destroy
Function: End the current session and clear all resources in the session.
Function prototype: boolean session destroy(void);
Return value: Boolean value.
Function description: This function ends the current session. This function has no parameters and the return value is true.
PHP processing session function 6, session_encode
Function: session information encoding
Function prototype: string session_encode(void);
Return value: string
Function description: The returned string contains the name and value of each variable in the global variable, in the form: a|s:12:”it is a test”;c|s:4:”lala”; a is the variable name s :12 represents the value of variable a. "The length of it is a test is 12. The variables are separated by semicolon ";".
PHP processing session function 7, session_decode
Function: session information decoding
Function prototype: boolean session_decode (string data)
Return value: Boolean value
Function description: This function can decode session information and return the logical value true if successful.
PHP processing session function 8. session_name
Function: access current session name
Function prototype: boolean session_name(string [name]);
Return value: string
Function description: This function can obtain or reset the name of the current session. If there is no parameter name, it means to get the current session name, and adding the parameter means setting the session name to the parameter name.
PHP processing session function 9, session_id
Function: Access the current session identification number
Function prototype: boolean session_id(string [id]);
Return value: string
Function description: This function can obtain or reset the identification number of the currently stored session. If there is no parameter id, it means that only the identification number of the current session is obtained. If the parameter is added, it means that the identification number of the session is set to the newly specified id.
PHP processing session function 10, session_unset
Function: Delete all registered variables.
Function prototype: void session_unset (void)
Return value: Boolean value
Function description: This function is different from Session_destroy in that it does not end the session. Just like using the function session_unregister to log out all session variables one by one.
The above content is the entire summary of PHP session functions. I hope you like it.