PHP 会话 ID 在每次请求时更改 [英] PHP Session ID changing on every request

查看:26
本文介绍了PHP 会话 ID 在每次请求时更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚将我的应用程序从本地 WAMP 迁移到了实际的在线服务器.这会导致会话 ID 未按显示方式保存的问题.

I have just migrated my application from a local WAMP to the actual online server. This has caused trouble with the session ID not being saved as it appears.

  • 我检查了 session_start 之前输出的不需要的字符
  • 我似乎在我的/tmp 中找不到任何保存的会话文件

这些是我的会话设置:

session.auto_start  Off Off
session.bug_compat_42   Off Off
session.bug_compat_warn On  On
session.cache_expire    180 180
session.cache_limiter   nocache nocache
session.cookie_domain   no value    no value
session.cookie_httponly Off Off
session.cookie_lifetime 0   0
session.cookie_path /   /
session.cookie_secure   Off Off
session.entropy_file    no value    no value
session.entropy_length  0   0
session.gc_divisor  1000    1000
session.gc_maxlifetime  1440    1440
session.gc_probability  1   1
session.hash_bits_per_character 5   5
session.hash_function   0   0
session.name    PHPSESSID   PHPSESSID
session.referer_check   no value    no value
session.save_handler    files   files
session.save_path   /tmp    /tmp
session.serialize_handler   php php
session.use_cookies On  On
session.use_only_cookies    On  On
session.use_trans_sid   0   0

  • 在线服务器正在运行:PHP 5.3.9 版,而 WAMP 是:PHP 5.3.5 版.
  • 通过查看每个页面加载中发送的标头和响应,我得到以下信息,set-cookie 发送适当的会话 ID,收到的响应发送一个新的,就好像没有请求一样.
  • 我在预览 URL(启用 SSL)上运行该站点.不知道有没有关系,我的域名还没注册.
  • 错误代码很简单:

    • The online server is running: PHP Version 5.3.9 while the WAMP is: PHP Version 5.3.5.
    • By viewing the headers sent and the response in every page load I got the following, the set-cookie sends the appropriate session id and the response received sends a new one as if nothing was requested.
    • I am running the site on a preview URL (SSL on). I don't know if this has anything to do, my domain is not registered yet.
    • Error code is as simple as:

      $sId = session_id();

      if ($sId == '') { session_start();}

      推荐答案

      我刚刚遇到并解决了完全相同的问题.

      I just had and solved the exact same problem.

      事实证明,cookie PHPSESSID(记录会话)已发送,但被服务器忽略,因此会话未维护,每次页面重新加载或更改时服务器都会重新启动会话.

      It turns out that the cookie PHPSESSID (that keeps record of the session) was been send but it was ignored by the server, so the session was not maintained and the server restarted the session every time the page reloads or changes.

      问题是我在 wp-config.php 中有这一行:

      The problem was that I had in my wp-config.php this line:

      @ini_set('session.cookie_secure','On');
      

      这意味着如果连接不安全,每个 cookie 都将被忽略,因此服务器 PHPSESSID cookie 和会话被重新启动.

      This means that if the connection is not secure, every cookies is to be ignored, therefore the server the PHPSESSID cookie and the session was restarted.

      检查您的 wp-config.php 或您的 init.php.是 cookie 的问题.

      Check your wp-config.php or your init.php. Is a problem with cookies.

      这篇关于PHP 会话 ID 在每次请求时更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆