Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Session #16

Open
suhao opened this issue May 17, 2022 · 0 comments
Open

PHP Session #16

suhao opened this issue May 17, 2022 · 0 comments

Comments

@suhao
Copy link
Member

suhao commented May 17, 2022

PHP session变量用于存储关于用户会话的信息,或者更改用户会话的设置。session变量存储单一用户的信息,并且对应用程序中的所有页面都是可用的。

Seeion变量

HTTP地址无法保存状态,web服务器无法根据url地址来获取用户及其目的。使用session解决了此问题,通过在服务器上存储的用户信息,在用户离开网站后删除。

session工作机制是:为每个访客创建唯一id,并基于这个id创建存储变量。id存储在cookie中,或通过URL传导。

启动会话

session_start();

存储session变量

$_SESSION['username']='username';

销毁session

unset($_SESSION['username']);

关闭会话

session_destroy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant