急!!正做的精神却被这卡住了,悲剧啊
急求教,实在不知道在//loginchk中第54那里有错(else($flag == 1))请帮帮忙//index用户登录界面
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>用户登录</title>
<form action="loginchk.php" method="post">
<p align="center">请输入你的用户名:
<input name="name" type="text" id="name">
</p>
<p align="center">请输入你的密码:
<input name="pwd" type="password" id="pwd" >
</p>
<div align="center">
<p>
<input type="reset" value="清除">
<input type="submit" value="提交">
</p>
<p><strong>
<a href="administrator.php">我要以管理员身份登录</a>
<a href="register.php">我要注册</a>
</strong></p>
</div>
</form>
//register注册界面
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<script language="javascript">
function check()
{
if(document.regform.name.value=='')
{
alert('用户名不能为空!');
document.regform.name.focus();
return false;
}
if(document.regform.pwd.value=='')
{
alert('密码不能为空!');
document.regform.pwd.focus();
return false;
}
if(document.regform.pwd.value!=document.regform.repwd.value)
{
alert('两次输入的密码不一致!');
document.regform.repwd.focus();
return false;
}
}
</script>
<tr>
<form action="regok.php" method="post" name="regform">
<p align="center">请输入你希望使用的用户名:
<input name="name[]" type="text" id="name">
</p>
<p align="center">请输入你希望使用的密码:
<input name="pwd" type="password" id="pwd" >
</p>
<p align="center">请再次输入你希望使用的密码:
<input name="repwd" type="password" id="repwd" >
</p>
<div align="center">
<p>
<input type="reset" value="重填" >
<input type="submit" value="我要注册" onclick="check()">
</p>
<p><strong>
<a href="chat.php">我要以管理员的身份登录</a>
</strong></p>
</div>
</form>
</td>
</tr>
//regok写入用户信息
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>用户注册执行结果</title>
<?php
$userfile = "user.txt";
$name = $_POST['name'];
$pwd = $_POST['pwd'];
$repwd = $_POST['repwd'];
if(($name == "") || ($repwd != $pwd))
{
echo "对不起,你输入的信息不完整!";
echo "<br><a href='register.php'>请重新进行注册</a>";
echo "<br><a href='chat.php'>或以[游客]身份登录</a>";
}
elseif(!file_exists($userfile))
{
echo "user.txt文件不存在!<hr><p>";
}
else
{
$fp = fopen($userfile,"a");
if(!$fp)
{
die("<br>不能打开用户文件。");
}
fwrite($fp,"\r\n");
fwrite($fp,$name."&&");
fwrite($fp,$pwd."&&");
fclose($fp);
echo "夜猫子友情提示:<hr><p>";
echo "[$name]用户注册成功";
echo "<br><a href='index.php'>请返回登录</a>";
echo "<br><a href='chat.php'>或以[游客]身份登录</a>";
}
?>
//leginchk验证用户界面
<?php
session_start();
session_register('name');
session_register('userid');
session_register('ctime');
?>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" >
<title>用户登录结果</title>
<?php
$userfile="user.txt";
$name=$_POST['name'];
$pwd=$_POST['pwd'];
$ctime=date("Y-m-d H:i");
$userid=$_SERVER['REMOTE_ADDR'];
if(!file_exists("user.txt"))
{
echo "user.txt文件不存在!<hr><p>";
}
$flag=0;
$users=file($userfile);
foreach($users as $user)
{
list($tname,$tpwd)=explode("&&",$user);
if(($name==$tname)&&($pwd=$tpwd))
{
$flag=2;
break;
}
else
{
$flag=1;
continue;
}
}
//判断验证结果
if($flag == 2)
{
$_SESSION['name']=$name;
$_SESSION['userid']=$userid;
$_SESSION['ctime']=$ctime;
//写入用户登陆记录文件
$ufile="user/$name.txt";
$fp=fopen($ufile,"a");
if(!$fp)
{
die("<br>不能打开用户文件。");
}
$str= "欢迎用户$name [ $userid ] 于时间[ $ctime ]进入视频播放系统!";
fwrite($fp,$str);
fwrite($fp,"\r\n");
fclose($fp);
else($flag == 1)
{
echo "用户登录失败!<hr><p>";
echo "用户名或密码不正确!";
echo "<br><a href='index.php'>请重新登录!</a>";
echo "<br><a href='register.php'>请先进行注册</a>";
echo "<br><a href='chat.php?login=yk'>或以[游客]身份登录</a>";
}
?>