search
Homephp教程php手册什么是Session

什么是Session

Jun 13, 2016 am 10:28 AM
sessionone timeWhatyesexplainfirst

首先解释一下什么是Session,如果你不知道的话。当一个访问者来到你的网站的时候一个Session就开始了,当他离开的时候Session就结束了。本质是来说,cookie是和浏览器有关系,而Session变量就可以存一些资源变量在服务器上面。PHP4用文件存储Session变量,但理论上可以用数据库或共享内存来做这件事。 所有的页面都用PHP4的Session必须用Session_start()功能函数来告诉PHP4引擎来取有关的Session到内存中 。函数Session_start()可以在cookie域里或请求的参数中取得Session_id为了响应http请求。如果不能找到 SessionID就新建一个Session。 什么是Session变量? Session变量是个有规律的全局变量,当一个Session变量被注册,用PHP4可以在所有的页面上得到Session 的值。用Session_register("variable_name")可以注册一个Session变量。在所有并发的的用Session就使用 Session_start()函数,变量的值将作为一个Session变量注册为Session。 我们能作什么? 通常有很多的方法来管理Session和Session变量,我将给你个例子。说你将建一个商业站点,象我这样的, 你可能想保持已经被承认的用户当前的名字,或有多少的新消息用户已经得到。为了不在从数据库里读取,你 有两个方法可以做: 1.1.你可以用三个cookie 。authenticated_user - 当前的用户名称 。num_messages - 他得到的信息的数量 。expire_time - 何时重新读取信息数量 2.2.用sessions和新建三个session变量 第一个方法安全性不好,一些人可以得到cookie进入他人的领域。 用sessions用户仅得到一个cookie,安全的多。 缺点 session给了你自由,过度的用session会影响脚本语言的使用。虽然PHP4的session有些限制,如你不能存对象 在session里。 自己试一试吧!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.