2009-02-23 131 views
0

我在其中一個應用程序中使用httprequest類來請求跨域頁面。基本上我需要根據用戶的登錄狀態通過跨域ajax請求包含兩個頁面。由於安全問題,這是不允許的。php httprequest類和會話

所以我做的是我創建了一個代理頁面,它使用httprequest類來請求包含基於用戶登錄狀態的兩個apges的遠程文件。

現在的問題是,每次httprequest類發出新的請求時,會話都會被破壞,所以一旦我登錄後,下次刷新頁面時,該類將發送一個新請求,從而創建一個新的會話,所以登錄的用戶正在註銷。

我需要做的是在多個http請求中維護同一個會話,直到用戶選擇註銷。

我在firebug中觀察到http請求正在發送PHPSESSID cookie,但沒有任何內容從服務器發送迴應。它有任何意義嗎?

我該如何使用php cookie來做到這一點?請幫助。

+2

這應該是http://thedailywtf.com/ – 2009-02-23 08:53:45

+0

其中HttpRequest類是你在用嗎? – 2009-02-23 08:54:29

回答

1

您需要在瀏覽器和該遠程服務器之間傳遞cookie。我的工作something similar權利,但現在我給你一個簡單的例子:

proxy.php

<?php 

session_start(); 

if (! isset($_SESSION['remote_session_id'])) { 

    $response = make_initial_request(); 

    /* 
    * This means to read the Set-Cookie header and store it in your own session 
    */ 
    $_SESSION['remote_session_id'] = $remote_session_id = get_remote_session_id($response); 

} else { 
    /* 
    * Inside this function you must send a Cookie header populated with the value 
    * of $remote_session_id. Its name is dependent on the remote server. 
    */ 
    $response = make_remote_request($_SESSION['remote_session_id']); 
}