我有一个登录保护后台网站写ASP经典运行在Windows上。登录状态存储在会话变量中。我还有一个PHP页面,应该只有登录用户才能访问。如何在PHP中签入客户端已登录到此网站?
可能会有多个用户同时访问该页面。
发布于 2016-05-05 21:33:42
假设PHP和ASP应用程序共享相同的域名,下面是一个逐步的指南。
创建一个名为sessionConnector.asp的asp文件。
2-在sessionConnector.asp中,将Session.Contents对象序列化为PHP可以反序列化的格式,例如JSON。您可以使用来自阿斯布森的阿斯布森。
<%@Language=VBScript CodePage=65001%>
<!--#include file="JSON.asp"-->
<%
Set JSONObject = jsObject()
For Each Key In Session.Contents
If Not IsObject(Session.Contents(Key)) Then 'skip the objects cannot be serialized
JSONObject(Key) = Session.Contents(Key)
End If
Next
JSONObject.Flush
%>3-创建一个名为GetASPSessionState()的PHP函数。
4-在GetASPSessionState()中,通过指定填充了$_SERVER["HTTP_COOKIE"]的Cookie报头(必须包含ASP会话的标识符)来为sessionConnector.asp发出HTTP请求,这样ASP就可以识别用户,并且响应将随用户而异。
5-在获取响应(JSON字符串)之后,使用解码反序列化并查找ASP变量。
function GetASPSessionState(){
if(stripos($_SERVER["HTTP_COOKIE"], "ASPSESSIONID") === false){
# since ASP sessions stored in memory
# don't make request to get ASP session state if the cookie does not contain ASPSESSIONID
# otherwise IIS will create new redundant sessions for each of your checks so it wouldn't be a memory-friendly way
# returning an empty array
return array();
} else {
$options = array('http' =>
array('method'=>"GET", 'header' => "Cookie: " . $_SERVER["HTTP_COOKIE"])
);
$cx = stream_context_create($options);
$response = file_get_contents("http://mywebsite.com/sessionConnector.asp", false, $cx);
return json_decode($response, JSON_FORCE_OBJECT);
}
}
$aspSessionState = GetASPSessionState();
if($aspSessionState["IsLoggedIn"] == true){
//user previously logged in with the ASP
}发布于 2021-09-12 07:52:52
我的解决方案是自动提交一个webform,无论是PHP到ASP,还是ASP到PHP,它都是双向工作的。
在前面的页面上,只需向body标记添加一个OnLoad,如下所示:
<body onload="document.xxx.submit()">其中"xxx“是表单的ID,包含要传递的隐藏字段。例如:
<form id="xxx" action="example.asp" method="post">这将在本地和跨域工作。
https://stackoverflow.com/questions/37052135
复制相似问题