什么是php中的会话和cookie,它们存储在哪里?
什么是php中的会话和cookie,它们存储在哪里?
What are sessions and cookies in php and where are they stored?
我搜索了,但找不到确切答案.
I searched but I can't find the exact answer.
Cookie存储在浏览器中,而不存储在PHP中.您可以通过在$_COOKIE['cookiename']
中查找来获取浏览器发送的cookie,但据我所知,您无法设置此类cookie –您需要使用setCookie()
,或者可能是header('Set-cookie: ...')
.
Cookies are stored in the browser, not in PHP. You can get the cookies the browser sent by looking in $_COOKIE['cookiename']
, but as far as i know you can't set cookies like that -- you need to use setCookie()
, or possibly header('Set-cookie: ...')
.
会话可以存储在任何地方,但是大多数情况下它们只是服务器文件系统中的文件;您的php.ini
(或ini_get()
函数)可能有助于找出位置.试试:
The sessions can be stored anywhere, but they're most often just files on your server's filesystem; your php.ini
(or the ini_get()
function) would probably be helpful in finding out where. Try:
$session_file_name = ini_get('session.save_path')."/sess_".session_id();