编程题 编写一个登入页面和登入服务,要求如下: 1.用户可以选择7天内记住密码 2.用户可以设置取消记住密码 3.用户可以设置自动登入 4.用户可以取消自动登入

时间: 2024-05-15 20:14:52 浏览: 7
以下是一个简单的登入页面和登入服务的代码,使用了HTML、CSS、JavaScript和PHP: HTML代码: ``` <!DOCTYPE html> <html> <head> <title>Login Page</title> <link rel="stylesheet" type="text/css" href="style.css"> <script src="script.js"></script> </head> <body> <div class="container"> <h1>Login Page</h1> <form action="login.php" method="post"> <label for="username">Username:</label> <input type="text" id="username" name="username" required> <br> <label for="password">Password:</label> <input type="password" id="password" name="password" required> <br> <input type="checkbox" id="remember" name="remember"> <label for="remember">Remember me for 7 days</label> <br> <input type="checkbox" id="autologin" name="autologin"> <label for="autologin">Auto login</label> <br> <input type="submit" value="Login"> </form> </div> </body> </html> ``` CSS代码: ``` body { background-color: #f2f2f2; font-family: Arial, sans-serif; } .container { width: 400px; margin: 50px auto; background-color: #fff; padding: 20px; border-radius: 5px; box-shadow: 0px 0px 10px #aaa; } h1 { text-align: center; margin-top: 0px; } form { text-align: center; } label { display: inline-block; width: 80px; text-align: right; margin-right: 10px; } input[type="text"], input[type="password"], input[type="checkbox"], input[type="submit"] { padding: 5px; border-radius: 5px; border: 1px solid #ccc; margin: 5px; } input[type="submit"] { background-color: #4CAF50; color: #fff; cursor: pointer; } ``` JavaScript代码: ``` window.onload = function() { var remember = document.getElementById("remember"); var autologin = document.getElementById("autologin"); if (localStorage.getItem("remember") === "true") { remember.checked = true; document.getElementById("username").value = localStorage.getItem("username"); document.getElementById("password").value = localStorage.getItem("password"); } if (localStorage.getItem("autologin") === "true") { autologin.checked = true; document.forms[0].submit(); } remember.onchange = function() { if (this.checked) { localStorage.setItem("remember", "true"); localStorage.setItem("username", document.getElementById("username").value); localStorage.setItem("password", document.getElementById("password").value); } else { localStorage.removeItem("remember"); localStorage.removeItem("username"); localStorage.removeItem("password"); } }; autologin.onchange = function() { if (this.checked) { localStorage.setItem("autologin", "true"); } else { localStorage.removeItem("autologin"); } }; }; ``` PHP代码: ``` <?php if ($_SERVER["REQUEST_METHOD"] == "POST") { $username = $_POST["username"]; $password = $_POST["password"]; // Check username and password with database here if (isset($_POST["remember"])) { setcookie("username", $username, time() + 7*24*60*60); setcookie("password", $password, time() + 7*24*60*60); } else { setcookie("username", "", time() - 3600); setcookie("password", "", time() - 3600); } if (isset($_POST["autologin"])) { session_start(); $_SESSION["username"] = $username; } // Redirect to home page after login header("Location: home.php"); exit(); } ?> ``` 说明: 1. HTML代码中包含一个表单,用于输入用户名、密码和勾选框,以及一个JavaScript脚本,用于处理勾选框的状态和保存用户名和密码。 2. CSS代码用于美化页面。 3. JavaScript代码在页面加载时检查本地存储中是否保存了用户名和密码,如果是则将其填充到表单中,并根据勾选框的状态保存或删除本地存储。 4. PHP代码用于处理表单提交,验证用户名和密码,并根据勾选框的状态设置或删除cookie和会话变量。最后重定向到主页。

最新推荐

recommend-type

数据库实验一实验一 熟悉数据库管理工具、数据库和表的基本操作 一、实验目的: 1.了解SQL Server或MYSQL数据库的基本知识; 2.熟悉SQL Se

实验一 熟悉数据库管理工具、数据库和表的基本操作 一、实验目的: 1.了解SQL Server或MYSQL数据库的基本知识; 2.熟悉SQL Server或MYSQL环境和系统结构; 3.掌握图形化交互工具的基本操作,学会数据库及表的...
recommend-type

编程笔记:DevExpress控件的cxGrid多行表头设置(一步一步教你做).doc

DevExpress控件的cxGrid多行表头设置,网上搜索一下很多,多是太简单,我自己摸索后的笔记分享给大家,共同学习 。
recommend-type

Python编程一级试卷1.docx

青少年编程能力等级测评线上测评服务平台是互联网技术、信息安全技术、人工智能技术的综合应用体现。目前,经过行业专家的指导把关,在专业团队的辛勤开发下,与测评项目配套的测评服务平台及信息化系统已经研发并...
recommend-type

MELIS 用户编程手册-驱动编程指南.pdf

《MELIS 用户编程手册》第六章《驱动编程指南》,适合于F1C100S、荔枝派nano的SDK编程
recommend-type

python练习题 :用户任意输入10个整数到列表中,然后由大到小排列并输出。

一:填空题: 1.python是一种面向_对象 __的高级语言。 2.python可以在多种平台运行,这体现了python的___可移植___特性。 3.python源代码被解释器转换后的格式为___.pyc______。 4.python3.x默认使用的编码是_UTF-8...
recommend-type

zigbee-cluster-library-specification

最新的zigbee-cluster-library-specification说明文档。
recommend-type

管理建模和仿真的文件

管理Boualem Benatallah引用此版本:布阿利姆·贝纳塔拉。管理建模和仿真。约瑟夫-傅立叶大学-格勒诺布尔第一大学,1996年。法语。NNT:电话:00345357HAL ID:电话:00345357https://theses.hal.science/tel-003453572008年12月9日提交HAL是一个多学科的开放存取档案馆,用于存放和传播科学研究论文,无论它们是否被公开。论文可以来自法国或国外的教学和研究机构,也可以来自公共或私人研究中心。L’archive ouverte pluridisciplinaire
recommend-type

MATLAB柱状图在信号处理中的应用:可视化信号特征和频谱分析

![matlab画柱状图](https://img-blog.csdnimg.cn/3f32348f1c9c4481a6f5931993732f97.png) # 1. MATLAB柱状图概述** MATLAB柱状图是一种图形化工具,用于可视化数据中不同类别或组的分布情况。它通过绘制垂直条形来表示每个类别或组中的数据值。柱状图在信号处理中广泛用于可视化信号特征和进行频谱分析。 柱状图的优点在于其简单易懂,能够直观地展示数据分布。在信号处理中,柱状图可以帮助工程师识别信号中的模式、趋势和异常情况,从而为信号分析和处理提供有价值的见解。 # 2. 柱状图在信号处理中的应用 柱状图在信号处理
recommend-type

HSV转为RGB的计算公式

HSV (Hue, Saturation, Value) 和 RGB (Red, Green, Blue) 是两种表示颜色的方式。下面是将 HSV 转换为 RGB 的计算公式: 1. 将 HSV 中的 S 和 V 值除以 100,得到范围在 0~1 之间的值。 2. 计算色相 H 在 RGB 中的值。如果 H 的范围在 0~60 或者 300~360 之间,则 R = V,G = (H/60)×V,B = 0。如果 H 的范围在 60~120 之间,则 R = ((120-H)/60)×V,G = V,B = 0。如果 H 的范围在 120~180 之间,则 R = 0,G = V,B =
recommend-type

JSBSim Reference Manual

JSBSim参考手册,其中包含JSBSim简介,JSBSim配置文件xml的编写语法,编程手册以及一些应用实例等。其中有部分内容还没有写完,估计有生之年很难看到完整版了,但是内容还是很有参考价值的。