我有一個簡單的登錄頁面,但我無法顯示登錄頁面。提交表單時,會顯示相同的登錄頁面。我必須點擊刷新或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);
}
?>
您可能想要繼續顯示登錄頁面的代碼,特別是選擇顯示內容的分支。 – Jon 2011-04-03 15:11:15
我會盡力,但我會花一點時間總結一下。我會回來一會兒。我的登錄表單使用標準提交樣式的ExtJs。動作url是一個php,它會顯示類似於的內容。如果使用緩存,index.php會重新顯示,並且登錄表單仍然存在。 F5將顯示正確的顯示。如果沒有chache,cookies就會消失,服務器不能知道用戶已經登錄(意味着F5會一直顯示登錄表單)。 – demotics2002 2011-04-03 15:18:34
你應該使用[header](http://www.php.net/manual/en/function.header.php)函數直接從PHP重定向。請參閱PHP手冊頁面上的Location re-direct示例。 – 2011-04-03 15:20:22