PHP子域会话消失 [英] PHP Subdomain session disappearing

查看:29
本文介绍了PHP子域会话消失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

index.php

session_start();

if(!isset($_GET['n'])) {
  $_SESSION['foo'] = "bar";
  header("Location: /index.php?n=D");
}

echo "FOO: ".$_SESSION['foo'];

此页面 index.php 用于子域.子域是根域中的一个文件夹,即

This page index.php is used in a subdomain. The subdomain is a folder in the root domain, i.e.

 - WWW
    - SUB DOMAIN
      - index.php

会话变量 foo 在页面调用时设置,然后在重定向标头后检查 - 并且它消失了.

The session variable foo is set on page call, then checked after a redirect header - and it's gone.

我试过了:

  • ini_set('session.cookie_domain','.example.com');
  • session_set_cookie_params()的各种组合
  • 位置:http://subdomain.example.com
  • 扯掉我的头发

但似乎没有任何效果.似乎是一个非常简单的问题 - 有人可以帮我找到丢失的 cookie/会话/变量吗?

but nothing seems to be working. Seems like a very simple problem - can someone help me find my lost cookie / session / variable ?

编辑

var_dump(session_get_cookie_params()) 收益

array(5) { ["lifetime"]=> int(0) ["path"]=> string(11) "/" ["domain"]=>
 string(23) ".example.com" ["secure"]=> bool(false) ["httponly"]=> bool(false) } 

我的 URL 中有一个破折号 - (my-example.com).这可能是问题吗?

My URL has a dash - in it (my-example.com). Could this be the problem?

还尝试在参数之前设置 session_name().还是不行.

Also tried setting session_name() before params. Still not working.

推荐答案

经过五个小时的自我尝试,我终于联系了我的托管服务提供商,他们看了看.

After five hours of trying myself, I finally contacted my hosting provider and they had a look.

判决?php.ini 中的 session.save_path 尚未设置.上面的脚本现在可以正常运行了.

The verdict? session.save_path in php.ini had not been set. The script above is now running properly.

如果有人想详细说明原因和方法以及诸如此类的事情,我很乐意为他们提供解决方案,否则我将不得不接受自己的解决方案.

If someone cares to elaborate on the whys and hows and whatnot, I'll be happy to give them the solution, otherwise I'll have to accept my own.

这篇关于PHP子域会话消失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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