2019独角兽企业重金招聘Python工程师标准>>>
PHP启用session后对响应头的影响
PHP启用session后,将会给响应头加上如下的http header
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
准备示例代码 "session.php" :
准备示例代码 "nosession.php"
通过PHP命令行 php -S 127.0.0.1:9999
启用临时server。
test@test:~/html$ ls
favicon.ico index.php nosession.php session.php
test@test:~/html$ php -S 127.0.0.1:9999
PHP 7.0.32-0ubuntu0.16.04.1 Development Server started at Thu Feb 21 20:57:07 2019
Listening on http://127.0.0.1:9999
Document root is /home/test/html
Press Ctrl-C to quit.
请求结果:
- 请求启用session的接口结果如下
test@test:~$ curl -i "http://127.0.0.1:9999/session.php"
HTTP/1.1 200 OK
Host: 127.0.0.1:9999
Connection: close
X-Powered-By: PHP/7.0.32-0ubuntu0.16.04.1
Set-Cookie: PHPSESSID=6htonb74ku0cvnu8vvkobkug92; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate
Pragma: no-cache
Content-type: text/html; charset=UTF-8
hello world: has session
test@test:~$
- 请求没有启用的session的接口的结果如下
test@test:~$ curl -i "http://127.0.0.1:9999/nosession.php"
HTTP/1.1 200 OK
Host: 127.0.0.1:9999
Connection: close
X-Powered-By: PHP/7.0.32-0ubuntu0.16.04.1
Content-type: text/html; charset=UTF-8
hello world: no session
test@test:~$