本文介绍了无法使用php访问会话数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working in a subfolder on my website: www.example.com/subfolder

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

Now, i want to set a session that is only accessible within www.example.com/subfolder

要实现这一目标,我做了以下事情:

To achieve this, i did the following:

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()'.

Now when i print the $_SESSION array, it does not display anything, Not even 'Array()'.

请问我在做什么不对?

谢谢

推荐答案

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

Have you used session_start() anywhere before that code ?

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

I also suggest using var_dump() instead of print_r() to debug values as print_r doesn't output null values, hence creating some confusion sometimes.

这篇关于无法使用php访问会话数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 04:12