Vetrivel
Vetrivel

Reputation: 1149

how to handle seesion in subdomains using php

i have domain like www.example.com. In that i have 3 folders employee/account/dashboard in each folder i have separate login page. the problem is if i logged in 2 panels like www.example.com/employee, www.example.com/dashboard then if i logged out from any one panel automatically session destroyed another panel also. so how to solve the above problem. Note: i used different session variable in each subfolder.

session_start();
session_unset($_SESSION['admin_name']); //logout page for dashboard
header("location:index.php");

session_start();
session_unset($_SESSION['employee_id']); //logout page for employee
header("location:index.php");

i want if i logout from one panel(dashboard), the another panel (employee) should not logout.

Upvotes: 4

Views: 64

Answers (1)

Dale
Dale

Reputation: 319

Rather than using session destroy, I would consider consolidating each of your login profiles into one session, under separate variables. Each login and associated profile could be managed within a single object or array depending on the complexity required. That way, you could simply eliminate the single array for each section.

For Example after a successful login on the dashboard:

session_start();
$_SESSION['dashboard']=array();
$_SESSION['dashboard']['id']='whateverfromdatabase';
$_SESSION['dashboard']['loginname']='whatever-else';

and a logout would be:

session_start();
$_SESSION['dashboard']=array();
header("Location: index.php");

Upvotes: 2

Related Questions