duanpen9294 2016-07-05 07:56
浏览 35

PHP的会话管理

my code is simple:

<?php
session_start();
session_regenerate_id();
?>

When the first time I request this page, the HTTP request with no cookie, then it will response with two 'set-cookie:PHPSESSID=xxxxxx' Then I thought that I may write code like this:

<?php
session_start();
if(!empty($_SERVER['HTTP_COOKIE'])){
    session_regenerate_id();
}
?>

While then, whether my HTTP request with cookie: PHPSESSID=xxxxxx or not, it will responses with only one 'set-cookie:PHPSESSID=xxxxxx'

However, my solution is very awkward. Any professional PHPer can tell me, how to write a professional code to handle the problem which is the HTTP request may with cookie 'PHPSESSID' or without cookie 'PHPSESSID'.

  • 写回答

2条回答 默认 最新

  • dongxing2302 2016-07-05 08:00
    关注

    Have a look at session_start()

    session_start() creates a session or resumes the current one based on a session identifier passed via a GET or POST request, or passed via a cookie.

    So when you not want that PHPSESSION-Cookie you need to remove session_start()

    评论

报告相同问题?

悬赏问题

  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?