2011-04-03 83 views
1

我有一個簡單的登錄頁面,但我無法顯示登錄頁面。提交表單時,會顯示相同的登錄頁面。我必須點擊刷新或F5才能看到登錄頁面。我嘗試了無緩存(meta標籤),但我的問題是,cookies也消失了(我無法存儲狀態)。html/php沒有緩存但保留cookie

順便說一句,我的登錄使用重定向。表單提交調用一個不同的頁面進行驗證,然後重定向回到同一頁面,但據推測與不同的內容(登錄表單不應該在那裏)。

我相信這是基本的,但很遺憾在別處找不到答案。

謝謝。

更新: 下面是一些代碼: 登錄頁的ExtJS的形式提交:

login.getForm().getEl().dom.action='bridge.php/login'; 
login.getForm().getEl().dom.submit(); 

bridge.php是休息客戶到另一臺服務器: 片段:

<?php 
//echo $HTTP_SERVER_VARS['PATH_INFO']; 


require_once "RESTclient.php"; 
require_once "http_request.php"; 

$rest = new RESTclient(); 
$http_req = new httpRequest(); 

//$headers = $http_req->headers(); 
$headers = apache_request_headers(); 

foreach($headers as $key => $value) { 
    if($key != "Cookie" && $key != "Content-Type"){ 
     unset($headers[$key]); 
    } 
} 

//$headers["Content-Type"] = ""; 

$inputs = array_merge($_GET, $_POST); 
//$inputs = array_merge($inputs, $_); 

$url = "http://another_server/rest_service_here"; 
$path = $HTTP_SERVER_VARS['PATH_INFO']; 
$server = $url.$path; 

$rest->createRequest("$server",$http_req->method(),$inputs); 
$rest->addHeaders($headers); 
$rest->setBody($http_req->body()); 
$rest->sendRequest(); 

// get the headers now 
$responseheaders = $rest->getResponseHeaders(); 
$responsecookies = $rest->getResponseCookies(); 

if ($responseheaders != null) { 
    foreach ($responseheaders as $key => $value) { 
     header($key.': '.$value); 
    } 
} 
if ($responsecookies != null) { 
    foreach ($responsecookies as $key => $value) { 

     $name = $value['name']; 
     $val = $value['value']; 
     setcookie($name, $val); 
    } 
} 
if($path=='/login') { 
    ?> 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
<html> 
<head> 
<title>Logging in</title> 
<meta HTTP-EQUIV="REFRESH" content="0; url=/new_index.php"> 
</HEAD> 
<BODY> 
Redirecting to homepage... 
</BODY> 
</HTML> 
    <?php 
} else { 
    $output = $rest->getResponse(); 
    //$output = $output." ".$http_req->method(); 

    // start doing something about the output. 
    //echo $http_req->body(); 
    //echo $http_req->raw(); 
    echo $output; 
    //var_dump($headers); 
} 

?> 
+2

您可能想要繼續顯示登錄頁面的代碼,特別是選擇顯示內容的分支。 – Jon 2011-04-03 15:11:15

+0

我會盡力,但我會花一點時間總結一下。我會回來一會兒。我的登錄表單使用標準提交樣式的ExtJs。動作url是一個php,它會顯示類似於的內容。如果使用緩存,index.php會重新顯示,並且登錄表單仍然存在。 F5將顯示正確的顯示。如果沒有chache,cookies就會消失,服務器不能知道用戶已經登錄(意味着F5會一直顯示登錄表單)。 – demotics2002 2011-04-03 15:18:34

+0

你應該使用[header](http://www.php.net/manual/en/function.header.php)函數直接從PHP重定向。請參閱PHP手冊頁面上的Location re-direct示例。 – 2011-04-03 15:20:22

回答

3

由於只要你在做以下事情...

  1. 始終設置/你輸出什麼

  2. 隨時重新直接後,你已經設置cookie之前刪除登錄cookie。理想情況下,這應該是對不同URL的頁面(即使它只是一個不同的查詢字符串),但如果沒有緩存的頁面應該是應該工作正常。

  3. 只要您通過exit重定向(通過header('Location: ...');調用)結束腳本處理。

..然後一切都會好的。這就是說,正如@Jon所說的發佈一些代碼,我們可以看看。

+0

謝謝middaparka。我必須先消化你的答案,然後再嘗試。 – demotics2002 2011-04-03 15:30:23

+0

哦,夥計!退出()做了竅門。謝謝!!! – demotics2002 2011-04-03 15:41:16

+0

@ demotics2002如果沒有退出,那麼遵循重定向的代碼仍然會執行 - 這只是瀏覽器不會*看到它。 – 2011-04-03 15:44:36