【问题标题】:Cannot access the session array with php无法使用 php 访问会话数组
【发布时间】:2011-09-17 12:13:18
【问题描述】:

我正在我网站上的一个子文件夹中工作:www.example.com/subfolder

现在,我想设置一个只能在 www.example.com/subfolder 中访问的会话

为了实现这一点,我做了以下事情:

private $sessiontimeout= 10800;
        private $subdomain = '/subfolder/';
        private $website = 'example.com';    

function __construct ($table)
            {print_r( $_SESSION );
                $this->table=$table;
                $this->savedusername= $this->getsession('logbook');
                session_set_cookie_params ( $this->sessiontimeout, $this->subdomain, $this->website, 0, 1 );
                ini_set('session.use_only_cookies', 1);
                if (!is_null ($this->savedusername))
                {
                    $resultobj=selectquery ("select last_login_one from $this->table where username=?", "s", (array) $this->savedusername);
                    if ($resultobj['obj']->num_rows() > 0)
                    {
                        $this->last_login=$resultobj['data'][0]['last_login_one'];
                    }
                }
            }

现在当我打印 $_SESSION 数组时,它不显示任何内容,甚至不显示 'Array()'。

请问我做错了什么?

谢谢

【问题讨论】:

  • 问题已解决 ::: 在打印函数之后调用 session_start()!
  • 哈哈。下次多花点时间调试;)

标签: php session


【解决方案1】:

您是否在该代码之前的任何地方使用过 session_start() ?

我还建议使用var_dump() 而不是print_r() 来调试值,因为 print_r 不输出空值,因此有时会造成一些混乱。

【讨论】:

    【解决方案2】:

    您需要先致电session_start(除非您将session.auto_start 设置为1)。

    【讨论】:

      【解决方案3】:

      _SESSION 是超全局的。它在全球范围内。

      所以,你可能忘记了session_start();

      【讨论】:

        猜你喜欢
        • 2016-12-25
        • 1970-01-01
        • 2019-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-04
        • 1970-01-01
        相关资源
        最近更新 更多