【发布时间】:2011-04-03 15:09:19
【问题描述】:
我有一个简单的登录页面,但无法显示登录页面。提交表单时,会显示相同的登录页面。我必须单击刷新或 F5 才能看到登录页面。我尝试了无缓存(元标记),但我的问题是 cookie 也消失了(我无法存储状态)。
顺便说一句,我的登录使用重定向。表单提交调用不同的页面进行验证,然后重定向回同一页面,但据说内容不同(登录表单不应该再存在了)。
我相信这是基本的,但很遗憾在其他地方找不到答案。
谢谢。
更新: 以下是一些代码: 登录页面有带提交的 ExtJs 表单:
login.getForm().getEl().dom.action='bridge.php/login';
login.getForm().getEl().dom.submit();
bridge.php 是另一个服务器的休息客户端: sn-p:
<?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);
}
?>
【问题讨论】:
-
您可能希望继续显示登录页面的代码,尤其是选择显示内容的分支。
-
我会尝试,但我会先花一点时间总结一下。我会在一段时间内回来。我的登录表单使用标准提交样式的 ExtJs。操作 url 是一个 php,它将显示类似 的内容。如果使用缓存,index.php 会重新显示,登录表单仍然存在。 F5 将显示正确的显示。如果没有缓存,cookie 就会消失,服务器无法知道用户已经登录(意味着 F5 一直显示登录表单)。
-
您应该使用 header 函数直接从 PHP 重定向。请参阅 PHP 手册页上的位置重定向示例。