How to use PHP sessions to display the current online users and use session in PHP. Summary: php session refers to a mechanism in which a user moves from the website to the closed website. It provides public variables that are applied by all webpages.
How to use PHP sessions to display the current online users and use session in PHP.
Summary
Php session refers to a mechanism in which a user moves from the website to the closed website. It provides a public variable storage mechanism that is applied by all webpages. So what is the usefulness of SESSION? Shopping cart is used for online shopping. you can add your purchased items to the shopping cart at any time and check out the items at the cashier. In the whole process, the shopping cart has always played the role of temporary storage of the selected item, and used it to track the user's movements on the website. this is the role of SESSION.
The invention of SESSION makes up for the limitations of the HTTP protocol. the HTTP protocol is considered to be a stateless protocol. after the server completes the response, the server loses contact with the browser. The invention of session allows a user to retain his/her information when switching between multiple pages.
In PHP3, the session function is not provided directly. we can only implement it with other measures, such as using PHPLIB. If PHP4 is compared with PHP3, the biggest improvement is to provide SESSION.
Basic Session knowledge
To apply the session, you must use PHP4.1 or later versions, and set register_globle = Off in php. ini to register_globle = On. In addition, session. cookie_path =/is not easy to change.
By default, session in PHP is a Cookie applied by the client. When a Cookie is disabled, it is passed through Query_String.
Php processes a total of 11 session functions. let's take a look at how many functions will be used first.
1. session_start
Function: start a session or return an existing session.
Function prototype: boolean session_start (void );
Return value: Boolean
Function Clarification: This function has no parameters and returns true. It is best to place this function first, and there cannot be any output before it, otherwise an alarm will be triggered, 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
2. session_register
Function: register a new variable as a session variable.
Function prototype: boolean session_register (string name );
Return value: Boolean value.
Function Clarification: This function adds a variable to the current SESSION in the global variable. the parameter name is the name of the variable to be added. if the variable is successful, the logical value true is returned. You can use $ _ SESSION [name] or $ HTTP_SESSION_VARS [name] to set values or assign values.
3. session_is_registered
Function: checks whether a variable is registered as a session variable.
Function prototype: boobean session_is_registered (string name );
Return value: Boolean
Function Clarification: This function can check whether a specified variable has been registered in the current session. the parameter name is the name of the variable to be checked. If the call succeeds, the logical value true is returned.
4. session_unregister
Function: Delete a registered variable.
Function prototype: boolean session_session_unregister (string name );
Return value: Boolean
Function Clarification: 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. if it is successful, true is returned.