Home  >  Article  >  Backend Development  >  PHP processing session function summary sharing

PHP processing session function summary sharing

墨辰丷
墨辰丷Original
2018-06-07 17:22:301350browse

This article mainly introduces the summary and sharing of PHP processing session functions. Interested friends can refer to it. I hope it will be helpful to everyone.

PHP processing session 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. Let me share with you a summary of the session functions of PHP.

When the client's cookies are disabled, they 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 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 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 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 what needs to be checked. variable name. If successful, the logical value true is returned.

PHP processing session function 4. session_unregister
Function function: Delete registered variables.
Function prototype: boolean session_session_unregister(string name);
Return value: Boolean value
Function description: This function deletes the variables in the 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 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 "it is a test. The length is 12. Variables are separated by semicolons ";".

PHP processing session function 7 , session_decode
Function function: decoding session information
Function prototype: boolean session_decode (string data)
Return value: Boolean value
Function description: This function can decode session information , the logical value true is returned if successful.

PHP processing session function 8. session_name
Function function: access the current session name
Function prototype: boolean session_name(string [name]);
Return value: string
Function description: This function can get or reset the name of the current session. If there is no parameter name, it means getting the current session name. If you add parameters, Indicates that the session name is set 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 only obtaining the current session's identification number. Identification number, adding parameters means setting the session identification number to the newly specified id.

PHP processing session function 10. session_unset
Function 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.

Summary: The above is the entire content of this article, I hope it will be helpful to everyone's study.

Related recommendations:

PHP implements the processing method after returning the array

thinkPHP implements multi-table query and Method of paging function

Method of non-refresh paging function implemented by PHP Ajax

The above is the detailed content of PHP processing session function summary sharing. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn