Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to share sessions between PHP and ASP.net application?

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

like image 991
citronas Avatar asked Mar 30 '10 10:03

citronas


People also ask

Can PHP and ASP.NET work together?

php) files with server-side code, it's possible in ASP.NET to put all your server-side code in a code-behind file. In the same way you don't have to put all your CSS and JavaScript in every HTML page but can put them in separate files which are included, you can do that with ASP.NET code.

Can you share the state between classic ASP pages and ASP.NET pages?

By using a . NET class that creates a request containing the ASP Session cookie and sends it to an ASP page to retrieve the ASP Session variable and an ASP page that authenticates the request and returns the Session variable, you can share Session state between ASP.NET and ASP apps.

Is PHP session server side?

Yes, the session data is on the server only.


1 Answers

I want to tell you, how I ended up doing it.

Both applications access a MySQL database and access a "session" table, which consists of a Guid, the ID of the user, and a confirmationString (I guess I encoded the IDUser in it, somehow) and a date.

Sessions are only started by the PHP application (due to the fact, that the PHP application is still the main application). A new session will result in a new entry in the log table. Every link in the PHP application, that links to the ASP.Net application contains GET-Parameters, containing the Guid etc.

The ASP.net application checks for the GET-Parameters and sets the IDUser in the ASP.Net Session, if the GET-Parameters point to an existing session.

The links pointing back to the PHP application use the same technique.

(There are also other things to consider, like timeouts or logouts, but that can be handled as well)

All in all, I'd say that my approach is useful and none of the customers complained since the deployment (over 1 year ago)

like image 181
citronas Avatar answered Nov 10 '22 17:11

citronas