这是我最后一次尝试作为最后的努力:
的index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Customer Login</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="wrapper">
<div class="login">
<form name="loginForm" action="loginCheck.php" method="post">
<?php require("protect/serverInfo.php"); ?>
Email: <input type="text" name="Email" maxlength="35" /><br />
Password: <input type="text" name="Password" maxlength="4" /><br />
<input type="submit" name ="submit"/>
</form>
</div>
</div>
</body>
</html>
loginCheck.php
<?php
session_start();
$_SESSION['email'] = $_POST['Email'];
$_SESSION['password'] = $_POST['Password'];
require("protect/serverInfo.php");
$myusername=$_POST[Email];
$mypassword=$_POST[Password];
$result = mysql_query("SELECT * FROM Customers WHERE Email='$myusername' AND Password=$mypassword");
$count=mysql_num_rows($result);
if($count==1){
header('Location: customer.php');
exit();
}
else{
header('Location: index.php');
exit();
}
?>
customer.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled 1</title>
<link href="stylesheet.css" rel="stylesheet" type="text/css" />
<?php
session_start();
$myusername = $_SESSION['email'];
$mypassword = $_SESSION['password'];
?>
</head>
<body>
<?php
echo"success";
?>
</body>
</html>
我只需要一种非常简单的方式来获得一个表单帖子,如果正确则检查帖子信息,然后重新定向,如果正确,并使用它传递帖子数据。我一直在尝试使用会话和重定向,但它不能正常工作。实现这一目标的最简单方法是什么?目前我一直在使用PHP来检查MySQL数据库的登录信息。
答案 0 :(得分:1)
在页面上执行任何其他操作之前,您需要使用“session_start()”。
其他一些事情,我避免在页面上存储密码..这似乎是一个安全问题。
您的登录表单应根据从queury返回的mysql信息生成$ _SESSION数据,而不是用户提交的表单信息。您需要检查客户数据库,以确保他们是实际客户。
另外,请避免使用“header()”函数,尤其是在使用会话时。我通常在php中有一个“重定向”功能,可以做这样的事情......
function redirect($url) {
echo "<script type='text'/javascript'>window.location='" . $url . "';</script>";
}