Table of Contents
回复讨论(解决方案)
Home Backend Development PHP Tutorial 有关php session和Cookie问题session_start开启后做什么事?

有关php session和Cookie问题session_start开启后做什么事?

Jun 23, 2016 pm 02:04 PM

是会在服务端去自动创建一个Session,然后再在客户端创建一个Cookie吗,求前辈
指教Session_start开启后客户端和服务端具体做的事,尽量详细点


回复讨论(解决方案)

在服务端创建一个文件来存储session(如果当前访问没有session)
再在浏览器建立一个cookies,    PHPSESSID=session_id()

session由语句命令建立和销毁,客户端自动产生一个记录session id的cookie,无需命令设置

session建立后就可以使用$_SESSION(数组变量,全局),可以赋值需要跨页面的数据,当然对于其他页面来说就是读取,其他页面也要声明session_start后才能使用$_SESSION

cookie中的session id无需理会,不需要做匹配或判断之类操作,但其他要保留到客户端的数据就需要使用相关的cookie语句赋值/读取,参考手册

这些咚咚函数语句不多,但要说明反而是长篇大论
你不如自己多写几个小程序测试理解更好,程序测试结果不理解再发上来问要比现在听废话好得多

session_start() 启用 session
session 中可保存用户的私用信息,别人是看不到的
是否在 cookie 中创建 sessionid 取决于相关设置

你只要知道 session 和 cookie 一样,都是用来保存用户私有信息的,只不过前者是保存在服务器中,后者是保存在浏览器中的

session_start() 启用 session
session 中可保存用户的私用信息,别人是看不到的
是否在 cookie 中创建 sessionid 取决于相关设置

你只要知道 session 和 cookie 一样,都是用来保存用户私有信息的,只不过前者是保存在服务器中,后者是保存在浏览器中的
哪里都见得到版主的回复!
版主真心帮助了许多人啊!

cookie,服务器会把cookie里的数据发送到客户端
session,服务器把数据保存在服务器,然后把一个ID发送到客户端

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 Article Tags

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)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Introduction to the Instagram API Introduction to the Instagram API Mar 02, 2025 am 09:32 AM

Introduction to the Instagram API

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles