简体   繁体   English

用于检索ASP.Net会话ID的PHP代码

[英]PHP code for retrieving ASP.Net Session ID

I am looking for a php function to get session id from a asp.net page. 我正在寻找一个PHP函数来从asp.net页面获取会话ID。 I used PHPSESSID to get php session id and it's giving the correct result as shown below: 我使用PHPSESSID获取php会话ID,它给出了正确的结果,如下所示:

$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/'; 
session_write_close();
echo $strCookie;
result: PHPSESSID=h7h1si1gqge0opqe7hedk46aa7; path=/

Now I want to get ASP.Net Session ID, and I don't know the php command to be frank. 现在,我想获取ASP.Net会话ID,并且我不知道php命令是坦率的。 I tried ASPSESSIONID, ASPSESSID, SessionID etc unsuccessfully. 我尝试了ASPSESSIONID,ASPSESSID,SessionID等失败。 Each time the result is blank as shown below, whereas I can see the ASP.Net_SessionId using firebug. 每次结果为空白时,如下所示,而我可以使用firebug查看ASP.Net_SessionId。 Plese somebody help me to get the ASP.net session id. 请有人帮我获取ASP.net会话ID。 I tried searching through the forum but didn't get anything. 我尝试在论坛中搜索,但没有得到任何帮助。

$cookie="ASP.NET_SessionId=". $_COOKIE["ASPSESSIONID"] ;
session_write_close();
echo $cookie;
result: ASP.NET_SessionId=

Tried this code as well, but not getting anything: 也尝试了以下代码,但没有得到任何结果:

if(stripos($data,"ASP.NET_SessionId"))
{
$retData = explode("ASP.NET_SessionId=", $data);
$sessionTempValue = explode(";",$retData[1]);

 //setup the cookie with the recd data here..

echo $sendCookie1 = "ASP.NET_SessionId=".$sessionTempValue[0].'; path=/';
setcookie("ASP.NET_SessionId",$sessionTempValue[0]);
}

EDIT: Thanks TVK, Icarus and Mike Brant for guiding me into right direction. 编辑:感谢TVK,Icarus和Mike Brant指导我朝正确的方向发展。 I modified my script little bit as shown below and now ASP.Net SessionId is being saved in the file cookiedk.txt, though, still it's not appearing in $_COOKIE. 我对脚本做了如下修改,如下所示,现在ASP.Net SessionId被保存在cookiedk.txt文件中,但是它仍然没有出现在$ _COOKIE中。

define('COOKIE_FILE', 'cookiedk.txt');
curl_setopt($ch, CURLOPT_COOKIESESSION, 1); 
curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE);

Below is cookiedk.txt content: 以下是cookiedk.txt的内容:

# Netscape HTTP Cookie File
# http://curl.haxx.se/rfc/cookie_spec.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_xyz.com   FALSE   /   FALSE   0   ASP.NET_SessionId   jq0jeb45lldjlo45wreqsl45

One more help, saving the session ID in a file may be problematic where multiple users will be interacting with the system at the same time. 将会话ID保存在文件中的另一种帮助可能会出现问题,即多个用户将同时与系统进行交互。 Is there a way to get it through the script and set it there itself instead of saving in file? 有没有办法通过脚本获取它并在其中进行设置而不是保存在文件中?

If the ASP session ID is in fact available, then it should be in the $_COOKIE variable. 如果ASP会话ID实际上可用,则它应该在$_COOKIE变量中。 To see all the contents of $_COOKIE , you can use print_r($_COOKIE); 要查看$_COOKIE所有内容,可以使用print_r($_COOKIE); . If the session ID is in there, you can now see it and select the correct array key. 如果会话ID在其中,则现在可以看到它并选择正确的阵列键。

Keep in mind though, that cookies are only being sent if the cookie's domain restriction is being satisfied. 但是请记住,仅在满足cookie的域限制的情况下才发送cookie。

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

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