How session works

Jul 23, 2019 pm 01:52 PM
php session

How session works

Recommended tutorial: PHP Tutorial

Session working principle

 1. Create Session

When When a user accesses a server, if the server enables Session, the server will create a SESSION for the user. When creating this SESSION, the server first checks whether the request sent by the user contains a SESSION ID. If it contains a SESSION The ID indicates that the user has logged in before and created a SESSION for this user. Then the server will search the SESSION in the server's memory according to the SESSION ID. If the client request does not contain the SESSION ID, it will be for this client. The client creates a SESSION and generates a SESSION ID related to this SESSION. This SESSION ID is a unique, non-repeating, and difficult-to-find regular string. This SESSION ID will be returned to the client for storage in this response, and it is COOKIE that saves this SESSION ID, so that during the interaction The browser can automatically send this identifier to the server according to rules.

 2. Use Session

We know that in IE, we can set Cookie in the Internet option of the tool. If disabled, will it happen that the client's cookies are disabled and the SESSIONID can no longer be used? I found some information indicating that there can be other mechanisms that can still pass the Session id back to the server when COOKIE is disabled.

A frequently used technology is called URL rewriting, which is to directly append the Session id to the end of the URL path as additional information for the URL path, in the form of:

 http://…. /xxx;jSession=ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng! -145788764;

The other is appended to the URL as a query string, in the form:

## http://…. . /xxx? jSession=ByOK3vjFD75aPnrF7C2HmdnV6QZcEbzWoWiBYEnLerjQ99zWpBng! -145788764

##  Another type is the form hidden fields. That is, the server will automatically modify the form and add a hidden field so that the Session id can be passed back to the server when the form is submitted.

 

How session works

##Session function

The fundamental function of Session is to store some information about user and server sessions on the server side. Typical applications are:

 

1. Determine whether the user is logged in.

 

2. Shopping cart function.

Session instance problem Existing system A, B; Assumption System A is a web system that can run independently, that is, it can handle sessions directly with the browser. System B is based on mobile and needs to call the functional interface of system A.

In the case of changes, that is, when the login verification and session storage remain unchanged, system B can handle the front-end user's request.

The solution provided here is to use PHP to implement

After the user successfully logs in, the session-id of the saved session is returned to system B. , and then system B will bring session_id every time it requests other interfaces.

System A adds session_id (session_id) before session_start;

In this way, system B can safely call A

Related topic recommendations
:

php session (including pictures, texts, videos, cases)

The above is the detailed content of How session works. For more information, please follow other related articles on the PHP Chinese website!

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 尊渡假赌尊渡假赌尊渡假赌

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)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

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 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 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 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.

See all articles