---
title: "Handle php session variable for two instance running on same server"  
description: "Handle php session variable for two instance running on same server"  
author: "Anonymous User"  
published: 2014-11-01  
updated: 2014-11-01  
canonical: https://www.mindstick.com/forum/2485/handle-php-session-variable-for-two-instance-running-on-same-server  
category: "php"  
tags: ["session", "session variable", "session management"]  
reading_time: 1 minute  

---

# Handle php session variable for two instance running on same server

For example let's [say](https://answers.mindstick.com/qa/116645/a1-wreckers-reviews-what-do-customers-say) I have an app that uses $_SESSION['user_id']. [Now](https://yourviews.mindstick.com/view/81402/it-s-liberals-vs-progressives-in-us-politics-now) if I have two of these [applications](https://www.mindstick.com/articles/12847/how-to-choose-the-right-ethernet-cable-for-industrial-applications) running on the same [server](https://www.mindstick.com/articles/43769/what-is-serverless-architecture-is-it-worth-switching-over) then they will be [sharing](https://www.mindstick.com/forum/157603/write-about-time-sharing-system-and-real-time-operating-system) this user_id [variable](https://www.mindstick.com/articles/1807/objective-c-data-types-variables-object-creation) which would break things.

The only thing I can think of is to prepend some [unique id](https://www.mindstick.com/forum/33873/how-to-get-unique-id-of-alasset-for-identification-in-ios) like this:

$_SESSION['/application1/user_id']

$_SESSION['/application2/user_id']

## Replies

### Reply by Pravesh Singh

This is the purpose of [session_name()](http://us3.php.net/manual/function.session-name.php). Assign a different name to each application's session to avoid collisions between $_SESSION keys. The name will be used as the session cookie's name so although both session cookies will be passed to both applications, only the one matching the application's session_name() will be used to populate $_SESSION.

```
session_name('application1');
session_start();

session_name('application2');
session_start();
```


---

Original Source: https://www.mindstick.com/forum/2485/handle-php-session-variable-for-two-instance-running-on-same-server

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
