0

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?

2
  • Are these two applications on the same server? Commented Jun 14, 2012 at 7:54
  • yes, there are connecting to PHP scripts from diferent webistes, but connection is to same server. Commented Jun 14, 2012 at 7:56

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

can you show me some example how to use session_name in my current situation?
0

Another solution is to set a cookie path (before session_start()).

Comments

0

In my experieance, If both of your application is on same virtual directory then it will be overwriten. So if you do not want to overwrite each other use different session variable.

Regards

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.