duanniling0018 2013-03-23 01:21
浏览 66
已采纳

PHP / Symfony2中每个用户两个会话

I'm using Symfony2, but this is probably just a PHP question.

  1. Based on my understanding (please correct if I am wrong) if I set the session cookie to secure then the cookie only gets sent on secure connections. So on non-secure connections the server in fact can't remember anything based on the user visit. I just want to confirm my understanding on this.

  2. Is it possible to have two session cookies? One for all protocols to store session data that isn't secure (e.g. isn't a user authentication/login) and the second session would be secure-only and handle the login authorisation.

    I know I could set a local cookie for the odd non-secure thing, but I'm really looking at being able to use $_SESSION twice (One for all and one for https-only).

    I feel that using secure cookie is essential for user authentication/login, but I also would like to be able to have some form of session on non-secure pages too.

  3. Does Symfony2 do anything in particular as to any of this? I know it handles sessions quite well through its in-built classes, but does it do anything particular in terms of using secure cookies?

  • 写回答

1条回答 默认 最新

  • dpgu5074 2013-03-23 11:47
    关注

    For (1) - Yes, you're correct

    For (2) - you can have 2 separated $_SESSION (secured and unsecured ones) communicate with each other by passing SessionID in your query string (probably with some hash protection to avoid the naughty users). Some more information here Session lost when switching from HTTP to HTTPS in PHP and Switching between HTTP and HTTPS pages with secure session-cookie

    As recommended in the threads, if possible, you can also make your life easier by considering to make your page HTTPS

    For (3) - I'm not an expert in Symfony2 but quick look through the documentation, it doesn't have any particular tool for you to use in this case, except the support to set if you want your cookie secured or not

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启
  • ¥15 51寻迹小车定点寻迹
  • ¥15 谁能帮我看看这拒稿理由啥意思啊阿啊
  • ¥15 关于vue2中methods使用call修改this指向的问题
  • ¥15 idea自动补全键位冲突
  • ¥15 请教一下写代码,代码好难
  • ¥15 iis10中如何阻止别人网站重定向到我的网站
  • ¥15 滑块验证码移动速度不一致问题