我之前用PHP写了一个会员登录界面,出现了问题,我以为我代码写错了,但是...
我从网上找了一个代码,也是出现了我一样的问题,但是他们运行是对的,他们的代码如下:要访问index.php页面,需要通过login.php登录,login.php调用ch...
我从网上找了一个代码,也是出现了我一样的问题,但是他们运行是对的,他们的代码如下:要访问index.php页面,需要通过login.php登录,login.php调用checklogin.php检验输入的用户名和帐号的合法性,checklogin.php调用conn.php连接数据库
login.php内容
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<form action="checklogin.php" method="post"><td align="center" valign="middle"><table width="400" border="0" cellpadding="5" cellspacing="1" class="tablebg">
<tr class="tdbg">
<td colspan="2"><div align="center">Administrators Login</div></td>
</tr>
<tr class="tdbg">
<td><div align="center">Username</div></td>
<td><div align="center">
<input name="username" type="text" id="username">
</div></td>
</tr>
<tr class="tdbg">
<td><div align="center">Password</div></td>
<td><div align="center">
<input name="password" type="password" id="passwd">
</div></td>
</tr>
<tr class="tdbg">
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
</div></td>
</tr>
</table></td></form>
</tr>
</table>
checklogin.php内容
<?
session_start(); //session函数
require_once('conn.php');
$username=$_POST['username'];
$password=$_POST['password'];
$exec="select * from users where username='".$username."'";
if($result=mysql_query($exec))
{
if($rs=mysql_fetch_object($result))
{
if($rs->passwd==$password)
{
$_SESSION["adminname"]="ABCDEFG";
if($_SESSION["adminname"]){
// echo $_SESSION["adminname"];
// header("location:index.php");
echo "<script>location.href='index.php';</script>";
}
else{echo "取session失败";}
}
else
{
echo "<script>alert('Password Check Error!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Username Check Error!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Database Connection Error!');location.href='login.php';</script>";
}
?>
conn.php内容
<?
$conn=mysql_connect ("localhost", "root", "");
mysql_select_db("数据库名字");
?>
index.php内容
<?
session_start();
if(($_SESSION["adminname"]=="") || ($_SESSION["adminname"] != "ABCDEFG")) {
echo " <script>alert('非法登入');location.href='login.php';</script>";
}
//echo $_SESSION["adminname"];
?>
我在浏览器中预览上述代码,不管在不在输入框输入用户名和密码,点了submit或clear了以后都是跳转到checklogin.php以后显示空白就没东西了,是不是我的数据库没设置好还是什么问题啊?请大虾们帮忙啊,我写的代码也是这样的问题。谢谢了哈!!!! 展开
login.php内容
<table width="100%" height="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<form action="checklogin.php" method="post"><td align="center" valign="middle"><table width="400" border="0" cellpadding="5" cellspacing="1" class="tablebg">
<tr class="tdbg">
<td colspan="2"><div align="center">Administrators Login</div></td>
</tr>
<tr class="tdbg">
<td><div align="center">Username</div></td>
<td><div align="center">
<input name="username" type="text" id="username">
</div></td>
</tr>
<tr class="tdbg">
<td><div align="center">Password</div></td>
<td><div align="center">
<input name="password" type="password" id="passwd">
</div></td>
</tr>
<tr class="tdbg">
<td colspan="2"><div align="center">
<input type="submit" name="Submit" value="Submit">
<input type="reset" name="Submit2" value="Clear">
</div></td>
</tr>
</table></td></form>
</tr>
</table>
checklogin.php内容
<?
session_start(); //session函数
require_once('conn.php');
$username=$_POST['username'];
$password=$_POST['password'];
$exec="select * from users where username='".$username."'";
if($result=mysql_query($exec))
{
if($rs=mysql_fetch_object($result))
{
if($rs->passwd==$password)
{
$_SESSION["adminname"]="ABCDEFG";
if($_SESSION["adminname"]){
// echo $_SESSION["adminname"];
// header("location:index.php");
echo "<script>location.href='index.php';</script>";
}
else{echo "取session失败";}
}
else
{
echo "<script>alert('Password Check Error!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Username Check Error!');location.href='login.php';</script>";
}
}
else
{
echo "<script>alert('Database Connection Error!');location.href='login.php';</script>";
}
?>
conn.php内容
<?
$conn=mysql_connect ("localhost", "root", "");
mysql_select_db("数据库名字");
?>
index.php内容
<?
session_start();
if(($_SESSION["adminname"]=="") || ($_SESSION["adminname"] != "ABCDEFG")) {
echo " <script>alert('非法登入');location.href='login.php';</script>";
}
//echo $_SESSION["adminname"];
?>
我在浏览器中预览上述代码,不管在不在输入框输入用户名和密码,点了submit或clear了以后都是跳转到checklogin.php以后显示空白就没东西了,是不是我的数据库没设置好还是什么问题啊?请大虾们帮忙啊,我写的代码也是这样的问题。谢谢了哈!!!! 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询