Home > Backend Development > PHP Tutorial > Introduction to php Session

Introduction to php Session

怪我咯
Release: 2023-03-14 07:12:01
Original
1929 people have browsed it

Introduction to php Session

What is Session

Session is difficult to translate directly into Chinese, and is generally translated into time domain. In computer terminology, Session refers to the time interval between an end user communicating with an interactive system, usually referring to the time elapsed from registering to enter the system to logging out exiting the system. Specifically, Session in the Web refers to the time that elapses from entering the website to closing the browser when a user browses a website, which is also the time spent by the user browsing the website. Therefore, we can see from the above definition that Session is actually a specific time concept.

It should be noted that the concept of a Session needs to include a specific client, a specific server and uninterrupted operation time. The Session in which user A establishes a connection with server C and the Sessions in which user B establishes a connection with server C are two different Sessions.
Before you store user information in a PHP session, you must first start the session.
Notes: session_start() Function must be placed before the label:

<?php session_start(); ?>

<html>
<body>

</body>
</html>
Copy after login

Storage Session Variables

<?php
session_start();
// store session data
$_SESSION[&#39;views&#39;]=1;
?> 
<html>
<body>

<?php
//retrieve session data
echo "Pageviews=". $_SESSION[&#39;views&#39;];
?>

</body>
</html>
 [html]
终结 Session
unset() 函数用于释放指定的 session 变量:
[code]
<?php
unset($_SESSION[&#39;views&#39;]);
?>
Copy after login

Related topic recommendations: php session (including pictures, texts, videos, cases)

The above is the detailed content of Introduction to php Session. 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