
作者:陈业贵 华为云享专家 51cto(专家博主 明日之星 TOP红人) 阿里云专家博主
学习学习怎么通过md5加密.怎么进行注册登录操作.
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="1.php" method="POST">
用户名: <input type="text" name="username" />
密码: <input type="password" name="password" />
<input type="submit" value="提交" />
</form>
</body>
</html>
<?php
if(!$_POST['username']||!$_POST['password'])//如果表单传下来没有数据。退出程序
{
exit();
}
$username=$_POST['username'];//获取用户名
$password=md5($_POST['password']);//获取密码(密码用MD5函数进行加密)
$link=mysqli_connect('localhost','root','root','a');//链接数据库root root代表数据库软件的账号+密码。a时数据库
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');//字符集时utf-8
$date=date('Y-m-d H:i:s');//设置当前时间给$date变量
$sql = "INSERT INTO login(username,password,time)
VALUES ('{$username}','{$password}','{$date}')";//插入数据库注册的用户名+密码+注册日期
$query=mysqli_query($link,$sql);//运行sql
echo "<script>alert('注册成功');location.href='11.php'</script>";<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<h1>这里时登陆页面</h1>
<form action="11.php" method="POST">
用户名:<input type="text" name="username">
密码: <input type="password" name="password">
<input type="submit" value="提交">
</form>
</body>
</html>
<?php
//用户输入的(表单传过来的)
$username=$_POST['username'];//获取用户名
$password=md5($_POST['password']);//获取密码·
//=========================
$link=mysqli_connect('localhost','root','root','a');//链接数据库root root代表数据库软件的账号+密码。a时数据库
//然后是指定php链接数据库的字符集
mysqli_set_charset($link,'utf8');//字符集时utf-8
//查询然后判断数据库中的用户名username+密码password是不是与表单传过来的$username+$password相匹配.
$sql="select username from login where username='{$username}' and password='{$password}'";//如果表单上下来的用户名sql与数据库中的sql匹配就登陆成功
$query=mysqli_query($link,$sql);//运行sql
$result=mysqli_fetch_array($query);//把对象变成数组,不然直接输出会报错
if($result)
echo $result?$result['username']."登录成功":"登录失败";
