2013-09-05 08:31
浏览 77


We have an ASP intranet web application that have been developed over years which is running on IIS6. Nowadays, we would like to add some new functionalities using PHP language instead. PHP is running fine on the same server. Sessions variables need to be shared between both ASP and PHP.

I am asking if there is other alternatives to share session between classic ASP and PHP instead of using database as gateway (too much resources consuming for us)? Both side need to read/edit session variables.

By tweaking a bit, I've noticed that a PHPSESSID and ASPSESSIONID is generated on PHP side every time a user is logged in the ASP web application. These are also visible on the ASP side, which are stored inside the server Variable HTTP_COOKIE, so I think there may be a correlation between ASP session and PHP sessions variables at the heart of IIS.


-- ASP --

<% Response.write ('HTTP_COOKIE') %> 


__utma=...; __utmz=...; computer%5Fid=AAA; lan=fre;ASPSESSIONIDXXXXXXXX=BBBBBBBBBBBBBBBBBBBBBBBB; user_login=cccc

-- PHP --

    echo '<pre>';
    var_dump($_COOKIE) ?>
    echo '</pre>';


    [__utma] => ...
    [__utmz] => ...
    [computer_id] => AAA
    [lan] => fre
    [user_login] => cccc

on ASP side, if I write :

<% Request.Cookies(strCookie)(strKey) %>

in a loop, it gives me bunch list of key/values session cookies stored.

But on PHP side, I can't find a way to get these key/value list. May be it is the way to go and find more? A real existing implementation would help more but any answers are welcome.

图片转代码服务由CSDN问答提供 功能建议

我们有一个多年来开发的ASP内部网Web应用程序,它运行在IIS6上。 如今,我们希望使用PHP语言添加一些新功能。 PHP在同一台服务器上运行良好。 会话变量需要在ASP和PHP之间共享。

我在询问是否还有其他方法可以在经典ASP和PHP之间共享会话,而不是使用数据库作为网关(消耗太多资源) 为了我们)? 双方都需要读取/编辑会话变量。

通过调整一点,我注意到每次用户登录ASP Web时都会在PHP端生成PHPSESSID和ASPSESSIONID 应用。 这些也可以在ASP端看到,它们存储在服务器变量HTTP_COOKIE中,所以我认为在IIS的核心ASP会话和PHP会话变量之间可能存在关联。


- ASP -



 <代码> __ UTMA = ...;  __utmz = ...; 计算机%5Fid = AAA; 兰= FRE; ASPSESSIONIDXXXXXXXX = BBBBBBBBBBBBBBBBBBBBBBBB;  user_login = cccc 

- PHP -

  echo'&lt; pre&gt;'; 
 var_dump  ($ _COOKIE)?&gt; 
 echo'&lt; / pre&gt;'; 


 [__utma] =&gt; ... 
 [__ utmz] =&gt; ... 
 [computer_id] =&gt; AAA 
 [lan] =&gt; fre 
 [user_login] =&gt; cccc 

在ASP端,如果我写: < pre> &lt;%Request.Cookies(strCookie)(strKey)%&gt;

在循环中,它给出了一系列键/值 会话cookie存储。

但是在PHP方面,我找不到获取这些键/值列表的方法。 可能是它的方式去寻找更多? 一个真正的现有实现将有所帮助,但欢迎任何答案。

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • douzhangcuo2174 2013-09-05 14:46

    I have used this before for the very same purpose. Try this link http://www.planet-source-code.com/vb/scripts/ShowCode.asp?txtCodeId=9028&lngWId=4

    点赞 打赏 评论
  • dsjgk330337 2013-09-06 09:28

    I've never used session variables in PHP before, so here I'm assuming that you have already assigned $var1 and $var2 the values of the session variables you want to pass to your ASP file.

    <iframe height="0" width="0" scrolling="No" src="setsession.asp?var1=<?php echo $var1; ?>&var2=<?php echo $var2; ?>"></iframe>

    Then your setsession.asp file would simply be

    Session("var1") = Request.Querystring("var1")
    Session("var2") = Request.Querystring("var2")

    Obviously you could do this the other way around, you just need to understand how to handle querystring and session variables in both languages

    点赞 打赏 评论
  • drpp5680 2017-02-13 12:22

    You can do this by calling session.asp from PHP script.

    PHP part:

    $link = "$http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    //here we get the url path
    for ($i=0;$i<count($ck);++$i) {
      if (strpos($ck[$i],"ASPSESSIONID")===0) {
        $cook .=$ck[$i]."=".$_COOKIE["$ck[$i]"].";"."<br>";
      }//we need to pass ASPSESSIONID cookies to ASP script
    $opts = array(
        'header'=>"Cookie: ".$cook
    //function for reading/writing ASP session values
    function aspsession() {
      global $urlp,$opts;
      if (func_num_args()==2) {
        return file_get_contents("$urlp../session.asp?n=$n&v=$v",NULL,stream_context_create($opts));
      } else {
        return file_get_contents("$urlp../session.asp?w=$n",NULL,stream_context_create($opts));
      }//put the right relative URL for session.asp
      //make sure it's in the same application as your other ASP scripts,
      //so it has the same session
    //to test if it works
    echo aspsession("a");

    ...and the session.asp:

    <% @Language = "VBScript" 
    <% Response.ContentType="text/plain" %>
    <% Response.Expires=-1 %>
    if n<>"" then
      Response.Write session(Request.QueryString("w"))
    end if
    点赞 打赏 评论

相关推荐 更多相似问题