2011-02-16 91 views
2

MSXML2.XMLHTTP.3.0對象如何連接到同一個會話?我想我自己的ActiveX控件展現出這種行爲。如何在我的ActiveX控件中使用Internet Explorer的Cookies?

的index.php:(服務器端語言是不相關的):

<?php session_start(); session_write_close(); ?> 
<html> 
<head> 
<title>Disp Test</title> 
<script type="text/javascript"> 
window.onload = function() 
{ 
    var divJS; 
    var objXHR; 

    divJS = document.getElementById('js'); 

    objXHR = new ActiveXObject("MSXML2.XMLHTTP.3.0"); 
    objXHR.open("GET", "ajax.php", false); 
    objXHR.send(); 
    divJS.innerHTML = objXHR.responseText; 
} 
</script> 
</head> 
<body> 
<p>Your session ID: <?php echo session_id(); ?></p> 

<div id="js"> 
Please enable Javascript. 
</div> 

</body> 
</html> 

ajax.php:

<?php session_start(); session_write_close();?> 
Your session ID from AJAX: <?php echo session_id(); ?> 

結果:

Your session ID: d2ljvbjllsdlc51rsq5naiffc2 

Your session ID from AJAX: d2ljvbjllsdlc51rsq5naiffc2 

回答

1

也許XMLHTTP對象是共享cookie的單身人士。我實現了我自己的ActiveX簡單地創建一個XMLHTTP對象,並將其只是工作當我在樣品中替換objXHR(以下僞代碼):

IXMLHTTPRequest* pX; 
hr = CoCreateInstance(CLSID_XMLHTTP, NULL, CLSCTX_INPROC_SERVER, IID_IXMLHTTPRequest, (void**)&pX); 
if(SUCCEEDED(hr)) 
{ 
    hr = pX->open("GET", "ajax.php", false); 
    if(SUCCEEDED(hr)) 
    { 
     hr = pX->send(); 
     if(SUCCEEDED(hr)) 
     { 
      VariantInit(pVarResult); 
      V_VT(pVarResult) = VT_BSTR; 
      hr = pX->get_responseText(&V_BSTR(pVarResult)); 
      if(!SUCCEEDED(hr)) 
      { 
       VariantClear(pVarResult); 
      } 
     } 
    } 

    pX->Release(); 
} 

return S_OK; 
相關問題