Same Domain, Different Folder PHP Session

Same domain, different folder PHP session

Set the path in the session cookie with session_set_cookie_params. Before session_start of course.

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.

Use the same PHP session on two different folders on the same server

There's nothing wrong with your php, but to debug this you need to understand this, for security reason http will not set cookie for top level domains, as a result you need to use second level domain as follow:

session_set_cookie_params(0, '/', '.mydomain.de');

you noticed I replaced www.mydomain.de by .mydomain.de

A little more

make sure you have the domains set up if they are not you can still use session_set_cookie_params(0, '/'); without indicating the subdomain index.

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.

DIfferent login (sessions) for different folders

Use different paths for the session cookie in the 2 applications.

Obviously you can't have the 2 settings in one php.ini file hence:

  • set the php_admin_value in a locationMatch directive in the httpd.conf (apache)
  • set the php_admin value in a .htaccess file
  • add a prepend to the PHP scripts (or amend a common include file) to set the path.

Note that if you're specifying the path in code, then session_set_cookie_params() is recommnded over ini_set(). Assuming the default config in php.ini is for the demo site (which should be using something like '/demo/' NOT '/')...

 if (false===strpos($_SERVER['REQUEST_URI'], 'demo') { 
// using live application
session_set_cookie_params (1200, '/live/');
}

(the above must be run before calling session_start())

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.

Ci using same session at different project

Try changing the sess_cookie_name value in your configs (by default this is in application/config/config.php).

Depending on your setup, you could be using the same store (database / redis) or with the files store the same sess_save_path in both projects. If you separate the project by session cookie's name they should not collide anymore.

Alternatively you could change the sess_save_path to an unique one for every project if you are using the files driver



Related Topics



Leave a reply



Submit