我正在尝试使用
header("Location: index.php")
在我的登录脚本中,但它不适用于我的实时服务器,只能在本地运行。我不知道为什么会有任何问题。
我也做了一些测试:
error_reporting(E_ALL);
ini_set('display_errors', 1);
// header('Location: test.php');
require_once 'class/functions.php';
$func = new Functions();
//$error = "";
if(isset($_POST['loginSubmitted'])) {
$user = $func->loginUser($_POST);
if($user == true) {
session_start();
$_SESSION['loggedin'] = true;
header("Location: index.php");
die('test');
}
else {
$error = 'Login nicht erfolgreich.';
}
}
显示了 die() 函数的“测试”,因此似乎甚至没有发送标头。
(不,在 header 函数之前没有输出)
编辑3:
使用 get 而不是 post 工作。我真的很困惑。
编辑2:
我制作了一个缩小版本进行测试,甚至以下内容也不起作用。似乎是服务器问题(与 $_POST 结合使用?!):
<?php
if(isset($_POST['submitted'])) {
header('Location: index2.php');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Login</title>
</head>
<body>
<form action="" method="post">
<input type="text" name="name" />
<input type="submit" name="submitted" value="senden" />
</form>
</body>
</html>
编辑:更新了代码示例。