Having Two Different Sessions in Same Domain

Having two different sessions in same domain

You could also use the same session but change the variable names that you look for.

Edit: Sorry this doesn't answer your question but gives an alternative solution.

Use different sessions for the same domain

You can set different session name for different apps in their config. For exaple for adv:

'session' => [
'name' => 'session_adv',
],

And for arch:

'session' => [
'name' => 'session_arch',
],

Two different PHP sessions in same domain, how to destroy only one of them?

It seems you have two applications on the same domain but want to operate two sessions entirely independently of each other. You are finding that logging off one app logs the user off the other app, but you don't want this to happen.

The solution is to set the session cookie only to be valid for the directory part of the domain for each app. By default, sessions extend across the whole domain, which is why destroying the session in one app affects the other one too.

For example, to log onto app 1, do this at the start of your session:

session_set_cookie_params (60 * 30, '/app1');

Of course, you will need to detect which app you are in, and serve the right path component accordingly. You can get this from a $_SERVER variable.

Read more here.

PHP - Separate session on the same domain

You could namespace your sessions, by using different session names.

Here's an example that looks to see if a parameter is set in the URL, and changes the session name accordingly.

<?php

$name = isset($_GET['foo']) ? 'foo' : 'bar';
session_name($name);
session_start();

You could have different session mechanisms, utilising a similar strategy.

Same Server, Different Domains Require Different Sessions

To avoid problems with sessions you should use the session_name('myapplication') [ session_name({UNIQUE_APP_ID}) ].

The problem you are mentioning can occur in more simple situations where there is an administration panel and a sign-in form for the users of the web site.

If session_name is not used a signed-in user could have access to the admin. panel but this depends on the auth. scheme and mechanism you have implemented.

regards,

PHP Sessions across subpages of same domain

The problem was that one section forced the URL to domain.com and the other forced it to www.domain.com.

How to manage a session in a same domain but different directory

If you have the possibility to use subdomains (app1.exapmple.com and app2.example.com), that is automatically solved.



Related Topics



Leave a reply



Submit