0

In PHP I can choose to use a particular Session by using Session_id() as a setter.

Is there any similar functionality in Classic ASP/VBScript? I have an VBScript site that, depending on the page, is either called directly from the browser or internally via HTTP. Unfortunately ASP treats these as two separate sessions, because the User's computer calls one and the Server itself calls the other. I want to tell the Server calls, "Hey, use Session 123456" so it can share info with the user calling pages directly.

Any advice? Any way to change or name the Session being used on a page?

Stephen R
  • 3,512
  • 1
  • 28
  • 45
  • Can you give an example? The Server calls aren't going to share cookies with the browser either... – Stephen R Apr 11 '17 at 23:01
  • 1
    There's no such built-in method for ASP's Session. But you can manually set `cookie` header (by parsing the session cookie's value from `Request.ServerVariables("ALL_RAW")` or something like) within your internal request. – Kul-Tigin Apr 11 '17 at 23:01
  • 1
    Where do you make internal requests from? Asking because, a deadlock happens if both are the ASP. – Kul-Tigin Apr 11 '17 at 23:13
  • That might work. So... get the VBScript session id and then manually pass the same cookie as I make the internal requests. Nice approach. Related? http://stackoverflow.com/questions/7331172/retrieiving-cookies-and-sending-cookies-and-post-variables-in-vbscript#7331976 – Stephen R Apr 11 '17 at 23:13
  • The overall issue is a web site running on both ASP and PHP. Sometimes PHP wants info or output from the ASP side; other times the page is just straight-up ASP. – Stephen R Apr 11 '17 at 23:18
  • Heh. I just noticed who wrote that comment I linked ;-) – Stephen R Apr 11 '17 at 23:19
  • 2
    :) There's no easy way to tell the Server "Hey, use Session #1". because of ASP's session stored in-process and the access is single threaded. While the request is working with session #1 you can't access session #1 from an additional request, a deadlock and finally request time out happens. But it's easy to access from somewhere else. PHP for example http://stackoverflow.com/a/37060660 – Kul-Tigin Apr 11 '17 at 23:30
  • BTW -- Please make this an Answer! – Stephen R Apr 12 '17 at 15:04
  • Short version: use this during PHP cURL setup: curl_setopt( $ch, CURLOPT_COOKIE, $_SERVER['HTTP_COOKIE'] ); – Stephen R Apr 12 '17 at 23:16

2 Answers2

3

There's no built-in method like PHP's Session_id() in ASP Classic.

ASP's Session object has a strict locking mechanism that guarantees consistency of the state, so this prevents you to make additional requests with the same session identifier within the same application pool.

On the other hand it's easy to implement a bridge to share the session state with a different platform like PHP under the same domain.


How to access ASP classic session variable from PHP?

Community
  • 1
  • 1
Kul-Tigin
  • 16,728
  • 1
  • 35
  • 64
0

I'm not sure that I understood your problem correct. You need a variable for each user? Why didn`t you use an application variable?

<%
    x=session.sessionID
    if not instr(application("x"),x)>0 then
       application("x")=application("x") & x &";"
    end if

    aArr=split(application("x"),";")

    for i=0 to ubound(aArr)
        REM this will show you all used session.variables
        response.write aArr(i)&"<br>"
    next
%>
  • ASP tracks sessions by setting a cookie on the user's browser that contains a session ID. Sometimes this particular web site works by one page (A PHP script generally) calling an ASP page directly server-side via cURL. In that case, the "user" is not the person with the browser, but the PHP script — which doesn't have the cookie I have on my browser. I need those cases to somehow have the same session as the human with a web browser. When ASP calls PHP, PHP can just set the session ID, but going the other direction, VBScript doesn't appear to be able to do that – Stephen R Apr 12 '17 at 11:01
  • why didn't you create an own session id? or use an application variable instead of session for example: if session("mySession")&""="" then session("mySession")=year(date)&month(date)&day(date)&replace(time,":","")&request.serverVariables("remote_addr") end if – multinett Apr 12 '17 at 12:40
  • Because you can't do that in Classic VBScript. That's literally the question! – Stephen R Apr 12 '17 at 12:45
  • did you read my example? setting your own session id like session("mySessionID")="test" is similar to session.sessionID. Session.sessionID is generated automatically but in fact only a counter. – multinett Apr 12 '17 at 12:50
  • Not at my computer at the moment to test, but is that Classic Asp or ASP.net? I've seen nothing to suggest you can set session id in Classic ASP – Stephen R Apr 12 '17 at 12:56
  • i use classic asp. i recommend, that you create your own session variable with session("myVariable")="12345". – multinett Apr 12 '17 at 13:42
  • I see what you're saying. This won't work -- it will still be two different sessions, and each separate session will have a variable called "myVariable". – Stephen R Apr 12 '17 at 14:05