php php中的会话和cookie有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4478805/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 13:09:04  来源:igfitidea点击:

What is difference between session and cookie in php?

php

提问by Md.Sakoat Hossen

Hi I would like to know the difference between a php sessionand a cookie

你好,我想知道aphp session和a的区别cookie

回答by netcoder

The main difference being that session data is stored on the server, while cookie data is stored on the client. Therefore, a client can easily modify the cookie contents, but will have to work way harder to modify the session contents.

主要区别在于会话数据存储在服务器上,而 cookie 数据存储在客户端。因此,客户端可以轻松修改 cookie 内容,但必须更加努力地修改会话内容。

回答by Naweed Chougle

Cookies are a means to store information in the end-user's browser, so that the server can track the end-user.

Cookie 是一种将信息存储在最终用户浏览器中的手段,以便服务器可以跟踪最终用户。

Sessions are also implemented by using cookies, but the actual data is not in the browser; rather, it is stored in the user's session record on the server. In the case of sessions, cookies are used to identify a particular end-user's session identifier on the server records. Hence, they are a more secure way of storing user information.

Sessions也是通过cookies来实现的,但实际数据不在浏览器中;相反,它存储在服务器上用户的会话记录中。在会话的情况下,cookie 用于在服务器记录上识别特定最终用户的会话标识符。因此,它们是一种更安全的用户信息存储方式。

回答by erenon

A cookie is a ~piece of data stored on the client side. Data stored in session is stored on the server side, and the various sessions are identified by cookies.

cookie 是存储在客户端的一段数据。session中存储的数据存储在服务器端,各种session通过cookies来标识。

回答by Vishal

There are session and Cookies, both are used to store values or data. But there are some key differences between session and cookie: a cookie stores the data in your browser and a session is stored on the server. Cookie data is available in your browser up to expiration date and session data available for the browser run, after closing the browser we will lose the session information.

有会话和 Cookie,两者都用于存储值或数据。但是 session 和 cookie 之间有一些关键的区别:cookie 将数据存储在浏览器中,而 session 存储在服务器上。Cookie 数据在您的浏览器中可用,直至到期日期和浏览器运行可用的会话数据,关闭浏览器后,我们将丢失会话信息。

回答by siva

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user's computer. Each time the same computer requests a page with a browser, it will send the cookie too.

cookie 通常用于识别用户。cookie 是服务器嵌入用户计算机的小文件。每次同一台计算机通过浏览器请求一个页面时,它也会发送 cookie。

A session variable is used to store information about, or change settings for a user session. Session variables hold information about one single user, and are available to all pages in one application.

会话变量用于存储有关用户会话的信息或更改其设置。会话变量保存有关单个用户的信息,并且可用于一个应用程序中的所有页面。

回答by Darin Dimitrov

A cookie is an unique information that the user sends to the web server with each request in order to identify him. This unique id could be used to store information about this specific user on the server (session).

cookie 是用户在每次请求时发送到 Web 服务器的唯一信息,以便识别他的身份。此唯一 ID 可用于在服务器(会话)上存储有关此特定用户的信息。

回答by jeswin

The main difference between a session and a cookie is that session data is stored on the server, whereas cookies store data in the visitor's browser. Sessions use a session identifier to locate a particular user's session data. This session identifier is normally stored in the user's web browser in a cookie, but the sensitive data that needs to be more secure — like the user's ID, name, etc. — will always stay on the server.

会话和 cookie 之间的主要区别在于会话数据存储在服务器上,而 cookie 将数据存储在访问者的浏览器中。会话使用会话标识符来定位特定用户的会话数据。此会话标识符通常以 cookie 形式存储在用户的 Web 浏览器中,但需要更加安全的敏感数据(如用户 ID、姓名等)将始终保留在服务器上。

回答by Disha Goyal

Cookies will only expire on expiry time or if you explicitly clean cookie / cache of your browser. Cookies will retain into the system even after you open your browser next day. Cookies are stored on client's system so they are less secure.

Cookie 只会在到期时间或在您明确清除浏览器的 cookie/缓存时过期。即使您第二天打开浏览器,Cookies 也会保留在系统中。Cookie 存储在客户的系统上,因此安全性较低。

Session will expire on its expiry time or if the browser has been closed. As session is stored on server so it is more secure.

会话将在其到期时间或浏览器已关闭时到期。由于会话存储在服务器上,因此更安全。

So for a login module, a combination of session and cookie should be used

所以对于登录模块,应该使用 session 和 cookie 的组合

回答by rajkumar

Cookies stored client side but session stored server side.

Cookie 存储在客户端,但会话存储在服务器端。

cookies is without sign out of the your email account and close it. once again can not enter username and password but your email account is open.

cookie 无需注销您的电子邮件帐户并关闭它。再次无法输入用户名和密码,但您的电子邮件帐户已打开。

session is close the webpage once again open to starting page appier

会话关闭网页再次打开到起始页面appier

回答by shahid nx

best example to illustrate the difference bet. Session and Cookies is:- when you Login as a member in any Site it Creates Sessions until you log out... that is Session..

最好的例子来说明不同的赌注。会话和 Cookie 是:- 当您在任何站点中以成员身份登录时,它会创建会话,直到您注销...即会话。

and Cookies when you browse websites the are stored on your computer's Main Memory that is Cookies

和 Cookies 当您浏览网站时,它们存储在您计算机的主内存中,即 Cookies

i-e Session is Server side and cookies is Client side

即会话是服务器端,cookie 是客户端