admin can able to see all his user profile in his site so he click the user link he can able to login as a user .now the issue is i had set the session name foe both user and admin as same . now i need to open the user profile in the private browser . other wise session conflict ill occur . so how can i open it in the private browser and i am unable to change the session name too.if i do need to chance the whole site .is it possible to do it or not
help me to do it
You can't do that. Its depend on User it will either open in private browser or default browser. You can not change behavior of browser. Especially as not all browsers even have such a feature!
You can not do that, You can not interfere the browser functioning and it depends upon the user in which mode he wants to open your website.
For what you want to do...
// have a session which specifies the type of user.
$_SESSION["utype"] = "admin" // or user
And use this to display the content accordingly.
You cannot force a link to open in private browsing mode in any browsers, so you would need to track your unique user sessions using the $_SESSION
as others have mentioned.
You will also need to implement a unique URL structure depending on the current user. Gmail implements this functionality by using the following URL structure:
The number /0/
shown in the URL refers to each of the users currently logged in. Keep in mind, that number is not a UserID or any potentially sensitive information, but simply an index to refer to the value in the session.
Behind the scenes, a simple example of the $_SESSION
would be as follows:
$_SESSION['authenticated_users'] = [
0 => [
'user_id' => 123,
'username' => 'John',
'user_role' => 'admin',
],
1 => [
'user_id' => 456,
'username' => 'Jill',
'user_role' => 'customer',
],
2 => [
'user_id' => 789,
'username' => 'Mark',
'user_role' => 'customer',
],
];
You would need to organise your code in such a way that it validated the current user between the URL requested, and authenticated users in the $_SESSION
.
In situations where only a single user was logged into the website (e.g. customers), you would not need to show the /0/
part in the URL.