Reputation: 2141
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
Upvotes: 3
Views: 452
Reputation: 50982
_SESSION is superglobal. It is in global scope.
So, you have probably forgot session_start();
Upvotes: 1
Reputation: 2490
You need to call session_start
first (unless you have session.auto_start
set to 1).
Upvotes: 1
Reputation: 1711
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.
Upvotes: 4