[英]How does PHP set the PHPSESSID into $_COOKIE superglobal variable without using the function setcookie() or setrawcookie()?
I'm learning PHP's most important and difficult to understand concepts viz. 我正在学习PHP最重要和最难理解的概念,即。 "Session and Cookies"
“会话和Cookie”
As per my understanding cookies can only be set into the browser by using either of setcookie()
or setrawcookie()
functions. 根据我的理解,只能使用
setcookie()
或setrawcookie()
函数将cookie设置到浏览器中。
As per my understanding of session process, it works in following way. 根据我对会话过程的理解,它的工作方式如下。
PHPSESSID
. PHPSESSID
。 To reference the session Id in my PHP code, I would therefore reference the variable $PHPSESSID (it's a cookie name) Please correct me if my understanding is wrong anywhere in above explanation. 如果以上说明中我的理解有误,请纠正我。
My doubt is as session is setting some value in $_COOKIE
superglobal it's nowhere using any of the functions setcookie() or setrawcookie()
then still how could session id gets stored as a cookie variable? 我的疑问是,由于会话正在
$_COOKIE
超全局变量中设置一些值,因此无法使用setcookie() or setrawcookie()
任何函数,那么会话ID仍如何存储为cookie变量?
If I assume that the session id is set as a cookie variable and setccookie() or setrawcookie()
might have been called internally then what are the parameter values set while calling either of the functions setccookie() or setrawcookie()
to set the cookie value? 如果我假设将会话ID设置为cookie变量,并且内部可能已调用
setccookie() or setrawcookie()
那么在调用函数setccookie() or setrawcookie()
来设置cookie时设置的参数值是什么?值?
Thank You. 谢谢。
The default name for the cookie is
PHPSESSID
.Cookie的默认名称是
PHPSESSID
。 To reference the session Id in my PHP code, I would therefore reference the variable$PHPSESSID
要在PHP代码中引用会话ID,因此,我将引用变量
$PHPSESSID
No, it is just the name of the cookie, it will not be set as a global variable. 不,它只是cookie的名称,不会将其设置为全局变量。 You can access the value in
$_COOKIE['PHPSESSID']
. 您可以在
$_COOKIE['PHPSESSID']
访问值。 But really, this should not concern you at all, you should only use the session_*
functions and the $_SESSION
superglobal to interact with PHP's session API, the underlying cookie being used is none of your concern for most intents and purposes. 但是,实际上,这根本不关心您,您只应使用
session_*
函数和$_SESSION
超全局变量与PHP的会话API进行交互,对于大多数意图和目的,所使用的基础cookie都不是您所关心的。
… it's nowhere using any of the functions
setcookie()
orsetrawcookie()
……在任何地方都无法使用
setcookie()
或setrawcookie()
函数……If I assume that the session id is set as a cookie variable and
setccookie()
orsetrawcookie()
might have been called internally …如果我假设将会话ID设置为cookie变量,并且内部可能已调用
setccookie()
或setrawcookie()
…
Yes, PHP is calling some functions internally that will set the cookies. 是的,PHP内部调用了一些将设置cookie的函数。 It's probably neither
setcookie
nor setrawcookie
but some internal C function that sets the cookie. 它可能既不是
setcookie
也不是setrawcookie
而是一些内部C函数来设置cookie。 Again, it's none of your concern really. 再次,这实际上与您无关。 You just need to understand that calling
session_start
will somehow internally cause a cookie to be set. 您只需要了解调用
session_start
会在某种程度上内部导致设置cookie。
… then what are the parameter values set while calling either of the functions
setccookie()
orsetrawcookie()
to set the cookie value?…那么调用函数
setccookie()
或setrawcookie()
设置cookie值时设置的参数值是多少?
Those are determined by the various session.cookie_*
parameters you can set via session_set_cookie_params
or ini_set
. 这些由您可以通过
session_set_cookie_params
或ini_set
设置的各种session.cookie_*
参数确定。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.