Reputation: 3239
I'm running a local apache server and have this folder structure:
localhost
site 1
index.php
site 2
index.php
Now, when I create a session in site 1/index.php
it also creates it for site-2
. How can I separate them?
Upvotes: 1
Views: 513
Reputation: 64
As mentioned - the simplest way is to try setting them up as vhosts with different domain names:
I'll use these two for my example:
testsite1.local
testsite2.local
( * Note, place this in your .conf file for Apache. Modify for your local envrionment. If on linux - /var/www/testsite1
, /var/www/testsite2
--- or wherever you keep your files. My config is from Xampp on Windows )
<VirtualHost testsite1.local:80>
ServerAdmin [email protected]
DocumentRoot "c:/xampp/htdocs/testsite1"
ServerName testsite1.local
</VirtualHost>
<VirtualHost testsite2.local:80>
ServerAdmin [email protected]
DocumentRoot "c:/xampp/htdocs/testsite2"
ServerName testsite2.local
</VirtualHost>
Add the local domains to your local routing (if on Windows, the hosts file in System32: /windows/system32/drivers/etc/hosts
- or on Linux - /etc/hosts
)
127.0.0.1 testsite1.local
127.0.0.1 testsite2.local
Restart your Apache.
Your server should automatically associate the sessions with the appropriate domains, as cookies where the sessions are stored are not allowed to be used by domains that do not match the cookie.
Upvotes: 0
Reputation:
The simplest solution if you publish this on the web is to different domains:
But if you want to do it on localhost:
This may help:
PHP How can I create multiple sessions?
Upvotes: 1