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() 函数之一设置到浏览器中。

根据我对会话过程的理解,它的工作方式如下。

以上解释如有错误请指正

我的疑问是,由于会话在 $_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决定。