When you run an app, you open it, make changes, and then close it. It's a lot like a session. The computer knows who you are. It knows when you start the application and when it terminates it. But on the Internet, there's a problem: the server doesn't know who you are and what you do, and that's because HTTP addresses don't maintain state.
PHP session solves this problem by storing user information on the server for subsequent use (such as user name, purchased items, etc.). However, session information is temporary and will be deleted after the user leaves the site. If you need to store information permanently, you can store the data in a database.
Copy the manual, try each one and write it out for your own reference. Who told us to just learn it? Session has about 12 functions:
session_start: initial session.
session_destroy: End session.
session_unset: Release session memory.
session_name: access the current session name.
session_module_name: access the current session module.
session_save_path: access the current session path.
session_id: access the current session code.
session_register: Register new variables.
session_unregister: Delete registered variables.
session_is_registered: Check whether the variable is registered.
session_decode: Session data decoding.
session_encode: Session data encoding.
There is also a global variable: $_SESSION
Before you can store user information in a PHP session, you must first start the session.
Note: The session_start() function must be placed before the tag:
Storing Session variables
End Session
The unset() function is used to release the specified session variable:
[code]
unset($_SESSION['views']);
?>
You can also terminate the session completely through the session_destroy() function:
Example:
Assume this page is called temp.php
< ;a href="temp.php?action=login">The user performs a login post, and the program handles writing to the session
Determine whether the user password is correct
Users who successfully log in log out Login
I summarized the usage of session in php.
(1) Start session
Before each use of session, add this sentence: "session_start();". As the name suggests, the function of this function is to start using the session.
(2) Register session
First, create a global (note, it must be defined as global, otherwise it cannot be used on other pages) array, such as $login, where $login['name']="Victor" , $login['pwd']="111111", and then call the function "session_register(login);", the session is successfully registered.
(3) Using variables in the session
Similar to registering a session, you must first create a global array, and then it is the same as using a normal array.
(4) Determine whether the session is registered
It is very simple, just use "if (session_is_registered(login))" to judge.
(5) Uninstalling session
It is also very simple, just "session_unregister(login);".
Note: Be sure to do (1) before doing (2) (3) (4) (5).
An example is given below:
index.htm
login.php
info.php
logout.php