session中应该存储哪些信息?
考虑到安全的问题,session(php编程)中应该存储哪些用户信息呢?
回复内容:
考虑到安全的问题,session(php编程)中应该存储哪些用户信息呢?
分开回答:
考虑到安全的问题
首先,session 不涉及到安全问题,session 和 cookie 相比很安全。
session(php编程)中应该存储哪些用户信息
- session 没有大小限制,所以,可以储存任意数量的数据
- session 没有类型限制,所以,可以储存任意类型的数据
- session 没有安全问题,所以,可以储存任意安全级别的数据
好像 session 可以储存任意数据,只是理论上,而且只是「可以」,但是我们讨论的是「应该」。
session 存储和用户会话相关的数据(session 的意思就是会话)。
@皮诺曹 说的
我手头的一个项目,是把模块的信息(属性、菜单、结合权限生成栏目列表)写入SEESION的。
但是这有个大前提是:这些数据是和特定用户相关。张三登录时,菜单是 A、B、C;李四登录时,菜单是 A、D、M,这时数据可以放入 session。
默认情况下SESSION保存在服务器的硬盘中,没有特别的存储长度限制,理论上可以存储任何数据,但并不建议任何数据都保存在SESSION中,原因不说了(考虑一下用户数及其庞大的情况下,每访问一个php文件,就要读取SEESION,特别是SEESION写入内存的情况下。),当然也可以写入memcache,甚至单独的SESSION服务器。
SESSION通常用来保存与用户信息相关的: 1. 身份信息、登陆状态 2. 用户的个性配置、权限列表 3. 其他的一些通用数据(比如购物车)
我通常把通用的、频繁存取的、小数据量的跟用户相关的数据放入SEESION,视场景而定,我手头的一个项目,是把模块的信息(属性、菜单、结合权限生成栏目列表)写入SEESION的。
基于REST考虑,应该放弃采用session,仅保留cookie中的sessionid用于用户识别。 其实上面说的把session放到redis、memcache等做法就是。 把session数据和其他业务数据同等对待。
--补充--
session的最大弊端在于集群环境中的session复制,这导致了对Share-Nothing Architecture的违反,严重拖累性能、可伸缩性。
session只是很小程度上简化了开发,同时也导致了开发人员的懒惰/放弃思考。
放弃session概念,把会话当作其他业务数据对待,根据业务场景设计正确的缓存策略、失效策略、集群存储等。
- 用 SESSION 的目的是缓存一些用户会话阶段的各种数据,比如头像、用户名、真实姓名、积分等等,所有这些数据都应该是只读操作,在有写操作时以数据库为准。
- 为防止有 SESSIONID 伪造,SESSION 要有 IP 及其它验证。
- 为了能实现多 WEB SERVER 下的用户数据一致,SESSION 从保存到本机的文件改为数据库或其它 NoSQL。
除了密码之外的..
session 是服务器端的,又不会直接暴露给用户,存什么都可以啊。
理论上,session 是可以存储任意的数据的; 但是,实际上,我们平常用到的数据有很多都是不用他的,因为session存储的数据是放在服务端的,每一次用到就需要打扰服务器,这是很消耗性能的;所以,session一般用于存储安全性要求比较高的而且数据量不是很大的数据。
session里“能”存的东西并无限制,session里“应该”存的东西是“少一点好”。
用多少取多少,用多少存多少~~
Session和用户的浏览器有关,跟用户的操作行为用关系。我这边经常拿来存放上下文。。
不如发送短信和验证短信两个步骤,
发送短信:记录已发送 xxxx 手机号的 session
验证短信:检验是否有 xxxx 手机号码的 session,校验客户端传送手机号码和 xxxx 是否一致。
完善点还要加上发送短信的实效性问题。繁殖频繁发送短信和校验短信。
其他信息如用户基本资料,个人觉得从 memcache 拿出来会好一点。
session 共享可以用 memcache 来实现,也可以用 nginx 的来实现。。
个人推荐用 nginx,结合 APC 共享内存机制。可以减少服务端的压力

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
