PHP Basic Tutorial PHP Session processing related functions introduction

Source: Internet
Author: User
Tags php session

PHP Basic Tutorial PHP Session processing related functions introduction

In PHP development, compared to cookie,session is stored on the server side of the session, relatively safe, and not like a Cookie has a storage length limit, here Brother even PHP small details about the PHP processing session function will use 10 functions.

PHP Development : PHP handles session functions 1, Session_Start

function function: Start a session or return a session that already exists.

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 better to put this function first, and before it can have no output, otherwise it will alarm, 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 functions 2, Session_register

function function: Register a new variable as a session variable

Function prototype: Boolean Session_register (string name);

Return value: A Boolean value.

Function Description: This function is to add a variable to the current session in the global variable, the parameter name is the name of the variable you want to add, and success returns the logical value TRUE. You can use $_session[name] or $http_session_vars[name] to take the form of a value or assignment.

PHP Processing session Functions 3, session_is_registered

function function: Check if the variable is registered as a session variable.

Function prototype: Boobean session_is_registered (string name);

Return Value: Boolean value

Function Description: This function checks to see if a specified variable has been registered in the current session, and the parameter name is the variable name to check. Success returns the logical value TRUE.

PHP Processing session Functions 4, Session_unregister

function function: Delete the registered variable.

Function prototype: Boolean Session_session_unregister (string name);

Return Value: Boolean value

Function Description: This function removes variables from global variables in the current session. The parameter name is the name of the variable you want to delete, and success returns TRUE.

PHP Processing session functions 5, Session_destroy

function function: Ends the current session and empties all resources in the session.

Function Prototype: Boolean session destroy (void);

Return value: A Boolean value.

Function Description: This function ends the current session, this function has no parameters and the return value is true.

PHP Processing session functions 6, Session_encode

function function: sesssion information encoding

Function prototype: string session_encode (void);

return value: String

Function Description: The returned string contains the names and values of the variables in the global variable, in the form of: 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 length is a semicolon between 12 variables"; Separated.

PHP Processing session Functions 7, Session_decode

function function: sesssion information decoding

Function prototype: Boolean Session_decode (String data)

Return Value: Boolean value

Function Description: This function decodes the session information and returns the logical value TRUE if successful.

PHP Processing session functions 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 no parameter name is given, the current session name is obtained, plus the parameter indicates that the session name is set to the parameter name.

PHP Processing Session Functions 9, session_id

function function: Access the current session identification number

Function prototype: Boolean session_id (string [id]);

return value: String

Function Description: This function can get or reset the identification number of the session currently stored. The absence of a parameter ID means that only the ID of the current session is obtained, plus the parameter indicates that the session's identification number is set to the newly specified ID.

PHP processing session functions 10, Session_unset

function function: Delete all registered variables.

Function prototype: void Session_unset (void)

Return Value: Boolean value

Function Description: Unlike Session_destroy, this function does not end the session. It's like using the function Session_unregister to unregister all session variables individually.


PHP Basic Tutorial PHP Session processing related functions introduction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.