views:

202

answers:

4

My company took some old php application over. Due to our preference to ASP.net and to the lack of any documentation from the previous developer, we do not want to spend much resources on developing in PHP. For implementing new features, we will create an Asp.net application that has the same look to the user. We want to develop a kind of 'coexisting' web application. Therefore we must share sessions between an PHP and an Asp.net webapplication project, because there is a usermanagement involved with an existing MySQL database.

(e.g. link 'A' directs to the PHP website, and link 'B' directs to the asp.net application)

How can we share the session between and PHP and an asp.net application?

And does anyone have a hint for this 'coexisting' thing, that might be useful in development?

Edit: IIS 6 would be our targeted server, altough IIS 7.5 would also be an option

A: 

http://cz.php.net/manual/en/function.session-set-save-handler.php
http://support.microsoft.com/kb/317604

You can write PHP's sessions into MsSQL, and configure .NET to use MsSQL as backend for sessions.

Yossarian
@Yossarian configuring a session state in MySQL isn't quite supported by ASP.NET as it uses several standard procedures and, if I'm not mistaken, it does use an `SqlConnection` object to connect to a **SQL Server** back end.
Paulo Santos
is there any reason you cannot connect to sql server from mysql via another connector, and read the same data as with SqlConnection?
Yossarian
+2  A: 

I don't think it's natively possible to share sessions between PHP and ASP.NET.

However, it might be possible by using a PHP page that reads the contents of the session, stores them in hidden fields and then call an ASP.NET page that would read these fields and load them into ASP.NET session.

Theoretically it's possible.

Paulo Santos
A: 

Not a big deal.
Your asp app should do a three simple things:

  • Recieve a sessionid cookie from the client
  • look for the sess_<id> file in the PHP session save path
  • implement a PHP serialize/unserialize functions to read/write session data.
Col. Shrapnel
A: 

Oh dear, maybe one day you'll see the error of your ways, in the meantime.....

By default, PHP writes its session data as a serialized array into a file named according to the session. The session is identified usually by a cookie with name PHPSESSID.

So in PHP to manually read the session:

$imported_session=unserialize(file_get_contents(session_save_path()) . '/' . $_COOKIE[session_name()]));

The format of the file is very straightforward and simple to parse.

However its quite easy to implement your own PHP session handler to write the files in any format/to any storage you like (have a look at auto-prepend for how to associate the revosed code with every page without having to rewrite each one). Or change the name the cookie used to store the session.

C.

symcbean
Would you mind explaning "Oh dear, maybe one day you'll see the error of your ways, in the meantime..."?
citronas