一、注册

1、注册界面

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="register_post.php" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="una"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pwd"></td>
</tr>
</table>
<input type="submit" value="提交">
</form>
</body>
</html>

2、注册处理

<?php
require_once "../DBDA.class.php";
$una=$_POST['una'];
$pwd=$_POST['pwd'];
//$pwd=md5($_POST['pwd']; //加密
//$pwd=md5(md5($_POST['pwd'])."123")."123";
$db=new DBDA();
$sql="select count(*) from t_user where una = '$una'";
$result=$db->StrQuery($sql);
if($result!='0'){
exit("用户名已占用");
}else{
$sql_insert="insert into t_user values (null,'{$una}','{$pwd}','')";
$result2=$db->Query($sql_insert, 0 );
var_dump($result2);
}

?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

</body>
</html>

二、登录

1、登录界面

<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form action="login_post.php" method="post">
<table>
<tr>
<td>用户名:</td>
<td><input type="text" name="una"></td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="pwd"></td>
</tr>
</table>
<input type="submit" value="登录">
</form>
</body>
</html>

2、登录处理

<?php
//var_dump($_POST);
require_once "../DBDA.class.php";
session_start();
$db=new DBDA();
$sql="select pwd from t_user where una = '{$_POST["una"]}' ";
$pwd=$db->StrQuery($sql);
//var_dump($pwd);
//var_dump($result);
if($pwd == $_POST["pwd"] && $pwd!=""){
echo "登录成功";
$_SESSION['user']=array(
'una'=>$_POST["una"],
);
// var_dump($_SESSION);
}else{
echo "登录失败";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>

</body>
</html>

3、退出处理

<?php
session_start();
unset($_SESSION);

?>