0
<?php
//index.php
session_start(); 
if (isset($_SESSION['username'])) {
header('Location: Pro_Lesson.php');
}
if (isset($_POST['username'], $_POST['password'])){
    if(empty($_POST['username']) || empty( $_POST['password'])){
        echo "username or password are empty";
    }else {
header('Location: login.php');
    }
}
?>
<html>
<head>
</head>
<body>
<h3>User Login</h3>
<table border="0">
<form method="POST" action="index.php">
<tr><td>Username</td><td>:</td><td><input type="text" name="username" size="20"></td></tr>
<tr><td>Password</td><td>:</td><td><input type="password" name="password" size="20"></td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td><td><input type="submit" value="Login"></td></tr>
</form>
</table>
</body> 
</html>

成功验证用户名和密码后,如何将表单数据发布到另一个 php 页面?它安全吗?

4

2 回答 2

2

你可以做到这一点:

$_SESSION['posted'] = $_POST;

在其他 php 页面中:

print_r($_SESSION['posted']);
于 2012-10-17T02:40:01.053 回答
0

我不确定你在问什么,但我会试一试。

您可能只关心用户名(或用户 ID)。您应该做的是将经过身份验证的用户存储在 cookie(或基于会话的 cookie)中。仅将用户的用户名(或用户 ID)存储在用户可编辑的 cookie 中是一个非常糟糕的主意 (tm)。您应该做的是在会话 ID 的后端有一个表,cookie 存储主 ID 的随机哈希,然后您可以使用它来查找您存储的有关该用户的信息。看似复杂,其实不然。如果您愿意,我可以对此进行更多扩展。

您可以按照 felipsmartins 的建议进行操作,但不应将用户密码存储在任何地方。

于 2012-10-17T02:43:24.550 回答