[Webinar] Streamline your web hosting managementRegister Today

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 631
  • Last Modified:

Share PHP session variablr across different domain names on same Apache server

I want to be able to share a session variable $_SESSION across different domain names on the same server.

I have different domains on the same server and I want to be able to share a session variable.


all www.siteX.com are on the same server and I want $_SESSION['share_foo'] to be shared across www.site1.com to www.siteN.com
3 Solutions
Ray PaseurCommented:
Can't be done without a lot of pain.  You need cookies for the session handler to work.  Cookies are set and retrieved on a per-domain basis.  So the difference between site1.com and site2. com is as big as the difference between google.com and facebook.com
Ray PaseurCommented:
Having said that, there are commercial networks that facilitate cookie sharing.  Are you familiar with how doubleclick works?
Tyler LaczkoCommented:
You can create update pages that would sync your SESSION variables from site1.com and site2.com

you could write the session variables out to a file and read out from that file etc.
2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

Ray PaseurCommented:

I would like to see an example of those solutions.  Can you please post working scripts that will do that?  Thanks, ~Ray
Sharing the session cache between domains and adding the session-ID to URL's should work (might need some altering of the session loading code). It's not very secure though.
pmsguyAuthor Commented:
I need to find out how to do this using symbolic links on the server.
Ray PaseurCommented:
Please give us an example of what you mean by "symbolic links on the server."
Ray PaseurCommented:
I object to deleting this.  Please give us an example of what you mean by "symbolic links on the server."  Are you familiar with how doubleclick works?  There may be answers, but we need to understand where you're coming from if we are going to be able to help, thanks. ~Ray
pmsguyAuthor Commented:
To the Community Support Moderator,

I take offense to your comment "Closing or deleting a question with a nonsense reason or without responding fully to the participants shows a lack of courtesy to those who tried to assist you"

Sometimes, a valid reason to close a ticket is "I did not get any helpful solutions".

Do NOT forget I am a paying customer.  I pay for this service.
This is not just a blog, I pay for this service to get expedited answers.

I reply to almost all of the questions with dignity and integrity.  
In this case, I did NOT get any feedback that helped me.  
To just randomly assign points to answers that were not helpful is counter productive, especially to paying customers.

A Paying Customer
Ray PaseurCommented:
@pmsguy: You asked a reasonable question, but we can't help you without knowing a little more about what you're trying to do, and that's why we need your answers to our questions.  If we can get those answers we might be able to help you make some progress.  BTW it is irrelevant that the domains are on the same server, and the information sharing will probably not be possible in the standard PHP session.  But it can be done with cookies and some custom code.

Please give us an example of what you mean by "symbolic links on the server."

Are you familiar with how doubleclick works?

Thanks, ~Ray (an unpaid volunteer)
pmsguyAuthor Commented:

I truly do appreciate your passion to answer questions.  As a paying customer I do need to get expedited time sensitive answers to mission critical rapid application development request from my boss.  Therefore, to have a mix of paying customers and volunteers  "producing revenue for Experts Exchange" sometimes becomes a conundrum.

Setting up symbolic links and configuring apache accordingly allows domains to share session variables.  However, when I do this the symbolic link url becomes www.mysite.com/link/siteA and all my javascript AJAX scenarios fail to work due to cross domain issues because the code is expecting the url to be www.siteA.com.

pmsguyAuthor Commented:
EE Admin,

Enough already with you trying to explain to me what professional courtesy is.

I am canceling my account because of Experts-Exchange's ridiculous badgering about protocol to reply to this question.

Yes - I am a paying customer.  If I feel a question I have has exhausted its purpose then I should have a right to delete this question if I feel I did not get any useful answers.  

It has become apparent to me, a PAYING customer, that Experts-Exchange 'uses' volunteers to produce revenue without the business professionalism to realize that the paying customer has different needs.

Just out of curiosity, pmsguy, could you explain why the cookie solution won't work for you, or why you refuse to give Ray any feedback on your symbolic links requirement?

I fail to see the point of being a "paying" customer, and then refusing to interact with the people that are trying to help you.

And something to consider:  you pay for the right to ask questions with money.  We pay for the same right with our time.  Your implication that your money is more valuable than our time is frankly insulting.
I second your statement TS.

pmsguy, considering that you have been advised in the past to respond to answers in you thread, you can hardly be surprised about the statements made in here.

Considering further that you asked 180+ complex questions in the past 3 years, which were answered by volunteers and which helped you perform your task at your workplace, is hardly low value for money.

The fact that you now throw the 'I pay for this' gauntlet around, will not help you to get more from EE. The fact that you only respond in anger when you are asked to do what is the simplest thing any community member, shows that you are not aware of what EE provides to you and only reiterates your disrespect to us, the volunteers.
The fact that you threaten to cancel the account as your idea of remedy only paints a poor and bitter picture of how you attempt to solve problems yourself, which is ironic considering you complain about our problem solving skills.

I suggest you take your attitude and spread it out on a table in front of you. Then have a long hard look at it and wonder if you would like to be at the receiving end if you were confronted with such.

If as a result you consider your posts here appropriate then you may never get the principle behind EE and maybe your money is ill-spent and you should look for help elsewhere.

CWS (haripriya)Commented:
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now