7 Replies - 441 Views - Last Post: 31 January 2012 - 03:33 PM Rate Topic: -----

Topic Sponsor:

#1 cancer10  Icon User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 50
  • Joined: 12-July 08

Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 10:38 AM

Hi

Is there anyway we can share a login session between two apps one of which is developed in php and the other one in Ruby or Perl or Python?


Thanks
Is This A Good Question/Topic? 0
  • +

Replies To: Sharing Sessions b/w 2 different apps?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2146
  • View blog
  • Posts: 5,429
  • Joined: 08-June 10

Re: Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 11:17 AM

not that I’m aware of, since every language usually has its own session implementation.

it might work if you have e.g. a database for storing session data, though that requires that both apps use the same serializer (which I doubt).
Was This Post Helpful? 0
  • +
  • -

#3 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 377
  • View blog
  • Posts: 739
  • Joined: 17-June 08

Re: Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 12:00 PM

View PostDormilich, on 31 January 2012 - 01:17 PM, said:

it might work if you have e.g. a database for storing session data, though that requires that both apps use the same serializer (which I doubt).

That isn't a problem. You can simply write your own session handlers and have them convert the serialized data to and from whatever format you use when storing the data. As long as the session handlers for both languages know know the persistence format and are able to convert it to whatever format the runtime expects, there should be no problems. Granted, it's a lot of extra work, as you have to write all your own session management code (in both languages), but it's totally manageable.

For examples, check out this article, which describes sharing session data between PHP and Python.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2146
  • View blog
  • Posts: 5,429
  • Joined: 08-June 10

Re: Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 12:38 PM

View PostAdaHacker, on 31 January 2012 - 08:00 PM, said:

As long as the session handlers for both languages know know the persistence format and are able to convert it to whatever format the runtime expects, there should be no problems.

I didn’t experiment with setting up my own serializer in PHP yet, so I can’t tell how easy that is.
Was This Post Helpful? 0
  • +
  • -

#5 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 377
  • View blog
  • Posts: 739
  • Joined: 17-June 08

Re: Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 02:06 PM

View PostDormilich, on 31 January 2012 - 02:38 PM, said:

I didn’t experiment with setting up my own serializer in PHP yet, so I can’t tell how easy that is.

Well, I didn't way that it was easy, just that it was manageable. :) Actually, I've never done it either (never had a reason to), but it's definitely possible.

Granted, trying to change the session data serialization on the PHP end would be a big pain in the neck. That's probably why the guys in the linked article changed it on the Python side - it's most likely going to be much easier in Python or Ruby than in PHP. To do it in PHP, you would need to parse the serialized session data in the session read and write handlers and convert it to the other format as it goes in and out of storage. The problem is that the session data serialization format is weird - it's similar to a string from serialize(), but not close enough to use serialize() directly and not distinct enough to reliably parse with a simple regex. I don't imagine it would be horribly difficult to write a parser for that format, but it's a non-trivial task.
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 1942
  • View blog
  • Posts: 7,296
  • Joined: 08-August 08

Re: Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 02:18 PM

Why do you want to do this? There's probably a better way for the two application to communicate.
Was This Post Helpful? 0
  • +
  • -

#7 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 2146
  • View blog
  • Posts: 5,429
  • Joined: 08-June 10

Re: Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 03:20 PM

View PostAdaHacker, on 31 January 2012 - 10:06 PM, said:

Granted, trying to change the session data serialization on the PHP end would be a big pain in the neck. […] To do it in PHP, you would need to parse the serialized session data in the session read and write handlers and convert it to the other format as it goes in and out of storage.

I dimly remember that you can set the serialize handler in php.ini. you could simply change it from the default to WDDX (which has a terrible space-efficiency (due to being XML), but is extremely portable (due to being XML))

View PostAdaHacker, on 31 January 2012 - 10:06 PM, said:

The problem is that the session data serialization format is weird - it's similar to a string from serialize(), but not close enough to use serialize() directly and not distinct enough to reliably parse with a simple regex.

I never directly looked at the saved data itself because I assumed PHP would call its standard serialize handler.
Was This Post Helpful? 0
  • +
  • -

#8 AdaHacker  Icon User is offline

  • Resident Curmudgeon

Reputation: 377
  • View blog
  • Posts: 739
  • Joined: 17-June 08

Re: Sharing Sessions b/w 2 different apps?

Posted 31 January 2012 - 03:33 PM

View PostDormilich, on 31 January 2012 - 05:20 PM, said:

I dimly remember that you can set the serialize handler in php.ini.

Doh! I totally forgot about that earlier. Yes, you're absolutely right. Just ignore me. :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1