PHP 如何在不使用函数 setcookie() 或 setrawcookie() 的情况下将 PHPSESSID 设置为 $_COOKIE 超全局变量?
How does PHP set the PHPSESSID into $_COOKIE superglobal variable without using the function setcookie() or setrawcookie()?
我正在学习 PHP 最重要和最难理解的概念,即。 "Session and Cookies"
据我了解,cookie 只能通过使用 setcookie()
或 setrawcookie()
函数之一设置到浏览器中。
根据我对会话过程的理解,它的工作方式如下。
- 每个会话都是使用 session_start( ) 函数启动的。
- session_start( ) 函数必须位于页面上任何 HTML 之前,包括空行。
- session_start( ) 函数生成一个随机会话 ID 并将其存储在用户计算机上的 cookie 中(这是唯一实际存储在客户端的会话信息。)
- cookie 的默认名称是
PHPSESSID
。要在我的 PHP 代码中引用会话 ID,因此我会引用变量 $PHPSESSID(它是一个 cookie 名称)
以上解释如有错误请指正
我的疑问是,由于会话在 $_COOKIE
超全局中设置了一些值,因此无法使用任何函数 setcookie() or setrawcookie()
那么会话 ID 如何存储为 cookie 变量?
如果我假设会话 ID 设置为 cookie 变量并且 setccookie() or setrawcookie()
可能已在内部调用,那么在调用任一函数 setccookie() or setrawcookie()
时设置的参数值是什么? cookie 值?
谢谢。
The default name for the cookie is PHPSESSID
. To reference the session Id in my PHP code, I would therefore reference the variable $PHPSESSID
不,它只是cookie的名称,不会被设置为全局变量。您可以访问 $_COOKIE['PHPSESSID']
中的值。但实际上,这根本不应该让你担心,你应该只使用 session_*
functions 和 $_SESSION
超全局与 PHP 的会话 API 交互,底层 cookie 是used 是 none 您关心的大多数意图和目的。
… it's nowhere using any of the functions setcookie()
or setrawcookie()
…
If I assume that the session id is set as a cookie variable and setccookie()
or setrawcookie()
might have been called internally …
是的,PHP 正在内部调用 一些 函数来设置 cookie。它可能既不是 setcookie
也不是 setrawcookie
而是一些设置 cookie 的内部 C 函数。同样,这确实是您关心的问题 none。您只需要了解调用 session_start
会以某种方式在内部导致设置 cookie。
… then what are the parameter values set while calling either of the functions setccookie()
or setrawcookie()
to set the cookie value?
这些由the various session.cookie_*
parameters you can set via session_set_cookie_params
or ini_set
决定。
我正在学习 PHP 最重要和最难理解的概念,即。 "Session and Cookies"
据我了解,cookie 只能通过使用 setcookie()
或 setrawcookie()
函数之一设置到浏览器中。
根据我对会话过程的理解,它的工作方式如下。
- 每个会话都是使用 session_start( ) 函数启动的。
- session_start( ) 函数必须位于页面上任何 HTML 之前,包括空行。
- session_start( ) 函数生成一个随机会话 ID 并将其存储在用户计算机上的 cookie 中(这是唯一实际存储在客户端的会话信息。)
- cookie 的默认名称是
PHPSESSID
。要在我的 PHP 代码中引用会话 ID,因此我会引用变量 $PHPSESSID(它是一个 cookie 名称)
以上解释如有错误请指正
我的疑问是,由于会话在 $_COOKIE
超全局中设置了一些值,因此无法使用任何函数 setcookie() or setrawcookie()
那么会话 ID 如何存储为 cookie 变量?
如果我假设会话 ID 设置为 cookie 变量并且 setccookie() or setrawcookie()
可能已在内部调用,那么在调用任一函数 setccookie() or setrawcookie()
时设置的参数值是什么? cookie 值?
谢谢。
The default name for the cookie is
PHPSESSID
. To reference the session Id in my PHP code, I would therefore reference the variable$PHPSESSID
不,它只是cookie的名称,不会被设置为全局变量。您可以访问 $_COOKIE['PHPSESSID']
中的值。但实际上,这根本不应该让你担心,你应该只使用 session_*
functions 和 $_SESSION
超全局与 PHP 的会话 API 交互,底层 cookie 是used 是 none 您关心的大多数意图和目的。
… it's nowhere using any of the functions
setcookie()
orsetrawcookie()
…If I assume that the session id is set as a cookie variable and
setccookie()
orsetrawcookie()
might have been called internally …
是的,PHP 正在内部调用 一些 函数来设置 cookie。它可能既不是 setcookie
也不是 setrawcookie
而是一些设置 cookie 的内部 C 函数。同样,这确实是您关心的问题 none。您只需要了解调用 session_start
会以某种方式在内部导致设置 cookie。
… then what are the parameter values set while calling either of the functions
setccookie()
orsetrawcookie()
to set the cookie value?
这些由the various session.cookie_*
parameters you can set via session_set_cookie_params
or ini_set
决定。