Home > Backend Development > PHP Tutorial > How to use PHP session to display currently online users_PHP tutorial

How to use PHP session to display currently online users_PHP tutorial

WBOY
Release: 2016-07-20 11:04:09
Original
1227 people have browsed it

Overview
PHP session, or SESSION, refers to a mechanism for user activities from entering the website to closing the website. It provides a common variable storage mechanism used by all web pages. So what is the use of SESSION? Everyone has used a shopping cart when shopping online. You can add the products you choose to the shopping cart at any time, and finally go to the checkout counter to check out. During the entire process, the shopping cart has been playing the role of temporarily storing the selected products, and using it to track the user's activities on the website, this is the role of SESSION.
The invention of SESSION filled the limitations of the HTTP protocol. The HTTP protocol is considered a stateless protocol. After it completes the response on the server side, the server loses contact with the browser. The invention of sessions allows a user to preserve his or her information when switching between multiple pages.
The session function is not directly provided in the PHP3 version. We can only use other methods to achieve it, such as using PHPLIB. If PHP4 is compared with PHP3, its biggest improvement is that it provides SESSION.
Basic knowledge of Session
To use session, you need PHP 4.1 or above, and you need to set register_globle=Off in php.ini to register_globle=On. Also, the line session.cookie_path = / is not easy to change.
Session in PHP uses client cookies by default. When the client's cookies are disabled, it will automatically be passed through Query_String.
Php has a total of 11 functions for processing sessions. Let’s introduce in detail a few functions that will be used.
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
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.
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 what needs to be checked. variable name. If successful, the logical value true is returned.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445230.htmlTechArticleOverview PHP session or SESSION refers to a mechanism for user activities from entering the website to closing the website. It provides a common variable storage mechanism used by all web pages. So...
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