I've got question to you. I have got two project in PHP that uses captcha, and write it to session. My question is, if I fire first application, that saves captcha to $_SESSION['code'] and then I start second application where I saves captcha to same variable, then the first value will be overwritten by second, or PHP will create two independent sessions?
-
Are these two applications on the same server?dpk2442– dpk24422012-06-14 07:54:27 +00:00Commented Jun 14, 2012 at 7:54
-
yes, there are connecting to PHP scripts from diferent webistes, but connection is to same server.Krystian– Krystian2012-06-14 07:56:27 +00:00Commented Jun 14, 2012 at 7:56
3 Answers
Normally, each application will override the session variables on the same server.
To avoid this, you can either namespace your sessions or use the session_name function.
You can namespace manually, by setting $_SESSION['app1']['code'] and $_SESSION['app2']['code'] or by using a session abstraction library like the one from Symfony or Zend Framework.
Using session_name in each application could look like this:
//Other init stuff here
define('APPLICATION_ID', "MY_UNIQUE_ID_1");
session_name(APPLICATION_ID);
session_start();
You'll have to change the unique id in some configuration file for each application. I put a define here to show that it doesn't come out of thin air.