10 functions for handling sessions in PHP

墨辰丷
Release: 2023-03-30 13:42:01
Original
1418 people have browsed it

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

In PHP development, compared to Cookie, Session is a session stored on the server side, which is relatively safe and does not have a storage length limit like Cookie. Here we introduce in detail the 10 session functions that PHP will use. function.

PHP processing session function 1. session_startFunction 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_registerFunction function: register a The new variable is the 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_registeredFunction 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_unregisterFunction: 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_destroyFunction 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_encodeFunction function: session information encoding
Function prototype: string session_encode(void);
Return value: string
Function description: returned The 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 variable a The value of "it is a test" is 12 and the variables are separated by semicolon ";".
PHP processing session function 7. session_decodeFunction: sesssion information decoding
Function prototype: boolean session_decode (string data)
Return value: Boolean value
Function description: This function can decode session information, and returns the logical value true 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 obtain or reset the name of the current session. If No parameter name means to get the current session name, and adding a parameter means setting the session name to the parameter name.
PHP processing session function 9, session_idFunction 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 The identification number of the session, and adding parameters means setting the identification number of the session to the newly specified id.
PHP processing session function 10, session_unsetFunction function: Delete all registered variables.
Function prototype: void session_unset (void)
Return value: Boolean value
Function description: This function is different from Session_destroy, it does not end the session. It is 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 can be helpful to everyone’s study.

Related recommendations:

How to use ftp to implement file upload and download functions in php

Detailed explanation of how PHP implements array deduplication

PHP file processing Class SplFileObject and SplFileInfo usage case analysis

The above is the detailed content of 10 functions for handling sessions in PHP. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!