简体   繁体   English

在ASP.NET应用程序中控制PHP会话

[英]Control PHP session in ASP.NET application

I maintain an online application that use most of the pages in PHP, but some pages uses for a good reason ASP.NET. 我维护了一个在PHP中使用大多数页面的在线应用程序,但有些页面使用的原因很好。 Users can login in the PHP part. 用户可以登录PHP部分。 Is there any option to control or a certain PHP session is active inside the ASP.NET page? 在ASP.NET页面中是否有任何控制选项或某个PHP会话处于活动状态? Both pages are hosted on one server. 两个页面都托管在一台服务器上。

You could build a web service on the PHP side that would allow to perform that check. 您可以在PHP端构建一个允许执行该检查的Web服务。

You would then call that webservice from the ASP.NET application. 然后,您将从ASP.NET应用程序中调用该Web服务。

You have to be very very careful however. 但是你必须非常小心。 A service like that would have to be highly secured, because this could provide a way to session hi-jacking, since it provides a way to validate if a certain session exists or not. 像这样的服务必须是高度安全的,因为这可以提供一种会话高压的方式,因为它提供了一种验证某个会话是否存在的方法。

You could secure it by only restricting allowed IP(s) or using a form of authentication. 您可以通过仅限制允许的IP或使用某种形式的身份验证来保护它。

There are different ways you can build webservice. 您可以通过不同的方式构建Web服务。

You could write it a simple page that just does whatever logic you want and then returns a result in JSON or XML (that's the lazy and ugly way of doing it). 你可以把它写成一个简单的页面,只做你想做的任何逻辑,然后用JSON或XML返回一个结果(这是一种懒惰和丑陋的方式)。 If you are using a particular framework, you could look to leverage that framework in order to add that service. 如果您使用的是特定框架,则可以利用该框架来添加该服务。 All major frameworks have ways to do that (Symfony, Silex, Laravel, Yii, Zend, etc.). 所有主要框架都有办法(Symfony,Silex,Laravel,Yii,Zend等)。 Zend Framework offers something called Apigility that makes building Restful webservices very easy. Zend Framework提供了一种叫做Apigility的东西,可以很容易地构建Restful Web服务。

Your ASP.net application, will also need to have a token coming from the PHP side, so it can be used to identify the session. 您的ASP.net应用程序还需要有来自PHP端的令牌,因此它可用于识别会话。

On the PHP side, you would need to store somewhere that the user is logged in. 在PHP方面,您需要存储用户登录的某个位置。

This also can be done in different ways and depends on what you want to achieve. 这也可以通过不同的方式完成,取决于您想要实现的目标。

For example, you could store in a database a timestamp along with a token indicating when was the last time you detected an activity from the user. 例如,您可以在数据库中存储时间戳以及一个标记,该标记指示您上次检测到用户的活动的时间。 Then, your webservice would check against that db for the token and see if the lastActivity timestamp has an adequate value (you would have to define what adequate means, eg not older than 30 minutes). 然后,您的Web服务将检查该数据库的令牌,并查看lastActivity时间戳是否具有足够的值(您必须定义适当的方法,例如不超过30分钟)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM