Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP code for retrieving ASP.Net Session ID
    text
    copied!<p>I am looking for a php function to get session id from a asp.net page. I used PHPSESSID to get php session id and it's giving the correct result as shown below:</p> <pre><code>$strCookie = 'PHPSESSID=' . $_COOKIE['PHPSESSID'] . '; path=/'; session_write_close(); echo $strCookie; result: PHPSESSID=h7h1si1gqge0opqe7hedk46aa7; path=/ </code></pre> <p>Now I want to get ASP.Net Session ID, and I don't know the php command to be frank. I tried ASPSESSIONID, ASPSESSID, SessionID etc unsuccessfully. Each time the result is blank as shown below, whereas I can see the ASP.Net_SessionId using firebug. Plese somebody help me to get the ASP.net session id. I tried searching through the forum but didn't get anything.</p> <pre><code>$cookie="ASP.NET_SessionId=". $_COOKIE["ASPSESSIONID"] ; session_write_close(); echo $cookie; result: ASP.NET_SessionId= </code></pre> <p>Tried this code as well, but not getting anything:</p> <pre><code>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]); } </code></pre> <p><strong>EDIT:</strong> Thanks <strong>TVK, Icarus and Mike Brant</strong> for guiding me into right direction. 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.</p> <pre><code>define('COOKIE_FILE', 'cookiedk.txt'); curl_setopt($ch, CURLOPT_COOKIESESSION, 1); curl_setopt($ch, CURLOPT_COOKIEJAR, COOKIE_FILE); </code></pre> <p>Below is cookiedk.txt content:</p> <pre><code># 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 </code></pre> <p>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. Is there a way to get it through the script and set it there itself instead of saving in file?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload