求助 php中session验证用户登录的使用```

高手介绍一下下面的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错误";
}
}
}
?>

代码没有问题。你所谓的“如果去悼session值”是去掉哪一段代码?试试这一行改一下。

if(md5($password) == $row["password"]) {

改成

if($password == $row["password"]) {
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-05-22
<?php
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"); ?>
第2个回答  2007-05-24

参考资料:

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网