[PHP加密]①--MD5
2017-09-12 本文已影响18人
子木同
Paste_Image.png
Paste_Image.png
mysql> create table user(
-> id smallint unsigned auto_increment key,
-> username varchar(50) not null,
-> password varchar(50) not null
-> );
reg.html
<html>
<head>
<title>reg</title>
</head>
<body>
<form action="doAction.php?act=reg" method="post">
<table cellspacing="0" cellpadding="0" width="80%" border="0">
<tr>
<td>
用户名:
</td>
<td>
<input type="text" name="username">
</td>
</tr>
<tr>
<td>密码:</td>
<td><input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="submit" value="注册"></td>
</tr>
</table>
</form>
</body>
</html>
login.html
<html>
<head>
<title></title>
</head>
<body>
<h1>慕课网登陆界面</h1>
<form action="doAction.php?act=login" method="post">
用户名:<input type="text" name="username">
<br/>
密码:<input type="password" name="password">
<br/>
<input type="submit" value="登陆">
</form>
</body>
</html>
doAction.php
<?php
header("content-type:text/html;charset=utf-8");
$act = $_GET['act'];
$username = isset($_POST['username']) ? $_POST['username'] : '';
$password = isset($_POST['password']) ? md5($_POST['password']) : "";
mysql_connect('localhost', 'root', '');
mysql_select_db('test');
mysql_set_charset("utf8");
if ($act == 'reg') {
$sql = "insert user(username,password) values('{$username}','{$password}')";
$result = mysql_query($sql);
if ($result) {
echo "注册成功,3秒后跳转到登陆界面";
echo "<meta http-equiv='refresh' content = '3;url=login.html' />";
} else {
echo "注册失败,请重新注册";
echo "<meta http-equiv='refresh' content = '3;url=reg.html' />";
}
} else if ($act == 'login') {
$sql = "select * from user where username='{$username}' and password='{$password}'";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if ($row) {
echo "登陆成功,3秒钟后跳转到首页";
echo "<meta http-equiv='refresh' content='3;url=http://www.imooc.com'/>";
} else {
echo "登陆失败,请重新登陆";
echo "<meta http-equiv='refresh' content = '3;url=reg.html' />";
}
}