我有一个用户对象,其中包含有关用户的信息(用户名,IP,国家,名称,电子邮件......但不是密码).我应该只在cookie中存储用户名,然后在加载页面时从数据库中检索所有信息,或者只是将整个用户对象存储在cookie中?
Pow*_*ord 17
您不能相信存储在cookie中的任何信息,因为用户可以在闲暇时操纵它.
我建议使用PHP 会话来存储对象.这样,最终用户只有一个存储在cookie中的会话ID,以及服务器上的真实数据.
会话最终会超时,但是......迫使用户再次登录.
编辑:哎呀,我应该指出会话真的很容易使用.只需执行以下操作:
session_start(); // This MUST be at the very top of every page that accesses the session
// Store something in the session with the key 'something'
$_SESSION['something'] = "Hi, I'm a session!";
// Retrieve 'something' from the session
$myString = $_SESSION['something'];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2682 次 |
| 最近记录: |