Same domain, different folder PHP session

I want to set a different session identifier depending on which folder the user is in.

For example, I have a domain https://example.com that has folders / app 1, / app2, etc., and then several files inside each application folder. I would like to set one session identifier that will be used with all files in application 1, and another session identifier that will be used in application2.

Can this be done?

+3
source share
5 answers

Set the path to the session_set_cookie_params session cookie. Until session_start , of course.

+4
source

If /app1 and /app2 contain completely unrelated applications, you can create completely unrelated sessions as with PHP session_name() , function. Sessions typically work with a cookie called PHPSESSID . Instead, in /app1 you can run session_name('session_app_1') and in /app2 you can run session_name('session_app_2') . Sessions in two applications will now be completely unconnected.

Warning: PHP documentation says that the session_name() function is expensive. Perhaps leave the session with the default name in the application of the busier user and rename it only to a quieter application.

+2
source

u can use the idea that $_SESSION var is an array:

 $_SESSION['app1'] = ... $_SESSION['app2'] = ... //etc etc 
0
source

I'm not sure that I understood the problem correctly, but you can try checking the path to see if it will be in app1, app2, etc., then get a part of the line you are interested in and use it to establish a session, for example, using $_SERVER['REQUEST_URI'] or $_SERVER['SCRIPT_NAME'] .

If you already do this, and your problem is that it just won't establish a session?

0
source

Setting session_save_path for different directories will serve your purpose. For example, you can install it in a subdirectory in each directory, i.e. relative path. Otherwise, to share sessions between directories, set session_save_path to the same full path. Works for me ..

0
source

All Articles