3

I am working in a subfolder on my website: 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'];
                    }
                }
            }

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

Please what am i not doing right?

Thanks

2
  • Question solved ::: was calling session_start() after the print function! Commented Sep 17, 2011 at 12:16
  • 1
    haha. take a bit more time to debug next time ;) Commented Sep 17, 2011 at 12:18

3 Answers 3

4

Have you used session_start() anywhere before that code ?

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.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to call session_start first (unless you have session.auto_start set to 1).

Comments

1

_SESSION is superglobal. It is in global scope.

So, you have probably forgot session_start();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.