随着渗透学习,逐渐意识到了学会开发也是非常重要的,仅仅是看懂感觉还是差了一些,所以写一写php的开发,这套程序目前并未有较完整的功能,之后会不断进行完善
登录页面.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test1</title>
</head>
<body background="http://img4.imgtn.bdimg.com/it/u=1806795254,1936125128">
<form action="login.php" method="post">
<fieldset>
<!--fieldest 组合表单中的相关元素 其中legend是该表中的标题-->
<legend>用户登录</legend>
<ul>
<li>
<label>username:</label>
<input type="text" name="username">
</li>
<li>
<label>password:</label>
<input type="password" name="password">
</li>
<li>
<label></label>
<input type="checkbox" name="rem" value="yes">in the next week ,auto login
</li>
<li>
<label> </label>
<input type="submit" name="login" value="登录">
</li>
</ul>
</fieldset>
</form>
<!--鼠标特效-->
<script src="https://blog-static.cnblogs.com/files/ophxc/shubiao.js"></script>
<canvas width="1777" height="841" style="position: fixed; left: 0px; top: 0px; z-index: 2147483647; pointer-events: none;"></canvas>
<!--鼠标特效 end-->
<!-- Music-->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer@1.10.0/dist/APlayer.min.css">
<script src="https://blog-static.cnblogs.com/files/zouwangblog/APlayer.min.js"></script>
<script src="https://unpkg.com/meting@1.2/dist/Meting.min.js"></script>
<div id="player" class="aplayer aplayer-withlist aplayer-fixed" data-id="2878443703" data-server="netease" data-type="playlist" data-order="random" data-fixed="true" data-listfolded="true" data-theme="orange"></div>
<!-- Music end -->
<img src="http://www.4kbizhi.com/d/file/2020/01/12/small00383295ltt1578760712.jpg" class="desc_img">
</body>
</html>
logout.php
<?php
header('Content-type:text/html; charset=utf-8');
session_start();
$username = $_SESSION['username'];
$_SESSION = array();
session_destroy();
setcookie('username', '', time() - 99);
setcookie('code', '', time() - 99);
echo "欢迎下次光临, " . $username . '<br>';
echo "<a href='登录页面.html'>重新登录</a>";
login.php
<?php
header('Content-type:text/html; charset=utf-8');
session_start();
highlight_file(login.php);
if(isset($_POST['username'])) {
$username = trim($_POST['username']);
#移除字符串两侧的空格
$password = trim($_POST['password']);
if (($username == "") || ($password == '')) {
header('refresh:5; url=login.html'); # 若为空,视为未填写,提示错误,并3秒后返回登录界面
echo "密码或用户名不能为空";
exit;
} else if (($username != 'username') && ($password != 'password')) {
header('refresh:3;url=login.html');
echo "用户名或密码错误";
exit;
} else if (($username = 'username') && ($password = 'password')) {
#session存取
$_SESSION['username'] = $username;
$_SESSION['login'] = 1;
if ($_POST['remember'] == "yes") {
setcookie('username', $username, time() + 7 * 24 * 60 * 60); #设置cookie存在时间
setcookie('code', md5($username . md5($password)), time() + 7 * 24 * 60 * 60);
} else {
setcookie('username', time() - 999);
setcookie('code', time() - 999);
}
header('location:index.php');
}
}
?>
index.php
<?php
header('Content-type:text/html; charset=utf-8');
session_start();
// 判断Cookie
if (isset($_COOKIE['username'])) {
# 若记住了用户信息,则直接传给Session
$_SESSION['username'] = $_COOKIE['username'];
$_SESSION['islogin'] = 1;
}
if (isset($_SESSION['islogin'])) {
// 若已经登录
echo "welcome " . $_SESSION['username'] . '!<br>';
echo "<a href='logout.php'>注销</a>";
} else {
// 若没有登录
echo "fail!<a href='登录页面.html'>登录</a>";
}
?>