Home Backend Development PHP Tutorial PHP cookie与session的有关问题

PHP cookie与session的有关问题

Jun 13, 2016 pm 01:31 PM
cookie js php session

PHP cookie与session的问题
PHP里,cookie与session相比,除了cookie保存在客户端,不占用服务端的硬盘外,还有啥优点?

PHP处理页面的时候,都是在服务端生成好页面后才发送给客户端,要是把数据缓存在cookie里,就要先把数据发送到客户端,下次访问的时候,再把保存在客户端cookie里的数据发送到服务端,处理后再回发给客户端……这样好像就要比用session缓存数据多了2次传送数据的过程?(session只是在服务器上读取,免去了网络传输?)

不知道这样理解对不对?要是真是这样的话,感觉用cookie缓存数据就没啥优势了……

恳请各位不吝赐教~

谢谢!

(有没有一种稍微简单的,把数据缓存在客户端,服务器处理php文件时不用从客户端再次读取,而是由客户端自动进行处理的技术啊?就是服务器在页面中需要缓存数据的地方留下标记,客户端读取到该标记的时候就去加载缓存的数据……)


------解决方案--------------------
如果把数据都保存在session 当然可以,前提是你是否有足够多的内存支持?

你说的可以使用js+cookie来实现,不过有个问题是cookie所能保存的内容也是有限的.另外也容易伪造
------解决方案--------------------
COOKIE是暴漏的啊,不安全啊,客户端编什么服务器信什么不就蛋疼了。
COOKIE就是一个可退化的会话技术,有没有都不会影响服务端的逻辑与安全。

如果一个用户登录以后,你发给用户一个COOKIE来标记用户已登录,那完蛋了。。
坏人只要分析出这个COOKIE的格式,用任何账号名都能编造出来,还玩毛啊。。

只要客户端能直接触碰的东西都是不安全的。
------解决方案--------------------
那么你如何在大量的缓存数据中删去已被删除的记录的相关内容呢?

特别是 每次查询数据库都涉及到大量的联合、笛卡尔积等操作的话 结果集的内容可能出现很大的变化(与被删除记录相关的联合、笛卡尔积部分都不存在了)
------解决方案--------------------
再者说 SESSION、COOKIE 是属于用户私有的
而删除记录是公有的事件,你总不能说甲删除记录时对乙就无效吧
假定现在有一万个用户在线,你打算如何去更新他们的缓存呢?

Statement of this Website
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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

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

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

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

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

CakePHP Logging CakePHP Logging Sep 10, 2024 pm 05:26 PM

Logging in CakePHP is a very easy task. You just have to use one function. You can log errors, exceptions, user activities, action taken by users, for any background process like cronjob. Logging data in CakePHP is easy. The log() function is provide

See all articles