Home >Backend Development >PHP Tutorial >How to replace php session with cache and cookies

How to replace php session with cache and cookies

WBOY
WBOYOriginal
2016-12-01 00:56:581387browse

The session concept no longer exists in the PHP 7 development framework I wrote myself

I want users to use caching + cookies to solve the problem

Actually, I want to know, simply maintain user login

Use cookies to symmetrically encrypt and store, then use PHP to decrypt and look up the table
There is actually no essential difference between recording the user uid in session and then looking up the table

Off topic

Cookies store the user’s hashed password and username. It is not impossible to simulate login every time

In fact, the database or cached data should be comparable to the practicality of session

After all, the session has a recovery mechanism. When 100,000 people log in to the website every day, the I/O bottleneck caused by the session mechanism may be more cruel than the bottleneck of the database

Another digression

Regarding the implementation of the shopping cart, it is actually possible to directly call the cache
key VALUE
User ID . Shopping cart content

I hope you guys can tell me what’s the point of still using session now, since it’s so random and unreliable

Reply content:

The session concept no longer exists in the PHP 7 development framework I wrote myself

I want users to use caching + cookies to solve the problem

Actually, I want to know, simply maintain user login

Use cookies to symmetrically encrypt and store, then use PHP to decrypt and look up the table

There is actually no essential difference between recording the user uid in session and then looking up the table


Off topic

Cookies store the user’s hashed password and username. It is not impossible to simulate login every time

In fact, the database or cached data should be comparable to the practicality of session

After all, the session has a recovery mechanism. When 100,000 people log in to the website every day, the I/O bottleneck caused by the session mechanism may be more cruel than the bottleneck of the database

Another digression

Regarding the implementation of the shopping cart, it is actually possible to directly call the cache

key VALUE

User ID . Shopping cart content

I hope you guys can tell me what’s the point of still using session now, since it’s so random and unreliable

1. Do not put information such as user passwords in cookies. Even if it is encrypted, there is a security risk.

2. Since you need to use caching, it is better to go to Redis directly. Product information and the user’s shopping cart can be placed in the Hash table of Redis

No problem, that’s what restful means.

I still use session because of convenience

Oh, and don’t check the table every time you simulate login. It’s better to use redis or something to save the recently logged in user information

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