高手介绍一下下面的session的使用详解,表的用户名,密码都不能登录,如果去悼session值,便可以登陆,请高手指点指点这是什么问题!~或是表建错了吗?应该怎么解决
<?php
session_start();
include("dbconnect.inc.php");
if($_GET["do"]=="logout") {
session_unset();
header("Location:index.php");
}
if($_GET["do"] == "1") {
$username = mysql_real_escape_string($_POST["username"]);
$password = $_POST["password"];
$message = "";
if($username == "") {
$message .= "用名不能为空<br />";
}
if($password == "") {
$message .= "密码不能为空<br />";
}
if($message == "") {
$sql = "select * from user where username='{$username}' and leves='admin' limit 1";
if($res=mysql_query($sql)) {
$row = mysql_fetch_array($res);
if(md5($password) == $row["password"]) {
$_SESSION["admin"]=1;
$_SESSION["username"]=$username;
header("Location:index.php");
exit;
}
$message = "用户名或密码错误";
}else {
$message = "验证失败,DB错误";
}
}
}
?>
if(md5($password) == $row["password"]) {
改成
if($password == $row["password"]) {
session_start();
include("config.inc.php");
include("dbconnect.inc.php");
if($_GET["do"]=="logout") {
session_unset();
header("Location:index.php");
}
if($_GET["do"] == "1") {
$username = mysql_real_escape_string($_POST["username"]);
$password = $_POST["password"];
$message = "";
if($username == "") {
$message .= "用名不能为空<br />";
}
if($password == "") {
$message .= "密码不能为空<br />";
}
if($message == "") {
$sql = "select * from user where username='{$username}' and leves='admin' limit 1";
if($res=mysql_query($sql)) {
$row = mysql_fetch_array($res);
if(md5($password) == $row["password"]) {
$_SESSION["admin"]=1;
$_SESSION["username"]=$username;
header("Location:index.php");
exit;
}
$message = "用户名或密码错误";
}else {
$message = "验证失败,DB错误";
}
}
}
?>
<?php include("header.inc.php"); ?>
<table width="778" border="0" cellpadding="0" cellspacing="6" class="border">
<tr>
<td valign="top" width="100%" class="listcontent" align="center">
<b><?Php echo $message; ?></b>
<table width="100%" border="0" cellpadding="6" cellspacing="0">
<tr>
<td class="listTitle">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><strong>管理员登陆</strong></td><td align=right> </td>
</tr>
</table>
</td>
</tr>
<tr>
<td valign="top" class="list">
<form action="login.php?do=1" method="post">
用户名:<input type="text" name="username" size="25" /><br />
密 码:<input type="password" name="password" size="25" /><br />
<input type="submit" value="登 陆" />
</form>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php include("footer.inc.php"); ?>
参考资料: