web-登陆界面html-数据库

概述

项目需要,于是花几天时间改站前端设计一个登录页面。页面设计首先通过html、css等语言完成,然后通过PHP调用后端数据库获取已授权用户信息,最后前端通过js的ajax调用php文件完成整个登录系统设计

效果实现

在这里插入图片描述

代码实现(html)

<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>login</title>
	<style type="text/css">
		@import url(http://fonts.googleapis.com/css?family=Source+Sans+Pro:200,300);
		* {
		  box-sizing: border-box;
		  margin: 0;
		  padding: 0;
		  font-weight: 300;
		}
		body {
		  font-family: 'Source Sans Pro', sans-serif;
		  color: white;
		  font-weight: 300;
		}
		body ::-webkit-input-placeholder {
		  /* WebKit browsers */
		  font-family: 'Source Sans Pro', sans-serif;
		  color: white;
		  font-weight: 300;
		}
		body :-moz-placeholder {
		  /* Mozilla Firefox 4 to 18 */
		  font-family: 'Source Sans Pro', sans-serif;
		  color: white;
		  opacity: 1;
		  font-weight: 300;
		}
		body ::-moz-placeholder {
		  /* Mozilla Firefox 19+ */
		  font-family: 'Source Sans Pro', sans-serif;
		  color: white;
		  opacity: 1;
		  font-weight: 300;
		}
		body :-ms-input-placeholder {
		  /* Internet Explorer 10+ */
		  font-family: 'Source Sans Pro', sans-serif;
		  color: white;
		  font-weight: 300;
		}
		.wrapper {
		  background: #50a3a2;
		  background: -webkit-linear-gradient(top left, #50a3a2 0%, #53e3a6 100%);
		  background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
		  position: absolute;
		  left: 0;
		  width: 100%;
		  height: 100%;
		/*  margin-top: -200px;*/
		  overflow: hidden;
		}
		.wrapper.form-success .container h1 {
		  -webkit-transform: translateY(85px);
		          transform: translateY(85px);
		}
		.container {
		  max-width: 600px;
		  margin: 0 auto;
		  padding: 80px 0;
		  padding-top:200px; 
		  height: 400px;
		  text-align: center;
		}
		.container h1 {
		  font-size: 40px;
		  -webkit-transition-duration: 1s;
		          transition-duration: 1s;
		  -webkit-transition-timing-function: ease-in-put;
		          transition-timing-function: ease-in-put;
		  font-weight: 200;
		}
		form {
		  padding: 20px 0;
		  position: relative;
		  z-index: 2;
		}
		form input {
		  -webkit-appearance: none;
		     -moz-appearance: none;
		          appearance: none;
		  outline: 0;
		  border: 1px solid rgba(255, 255, 255, 0.4);
		  background-color: rgba(255, 255, 255, 0.2);
		  width: 250px;
		  border-radius: 3px;
		  padding: 10px 15px;
		  margin: 0 auto 10px auto;
		  display: block;
		  text-align: center;
		  font-size: 18px;
		  color: white;
		  -webkit-transition-duration: 0.25s;
		          transition-duration: 0.25s;
		  font-weight: 300;
		}
		form input:hover {
		  background-color: rgba(255, 255, 255, 0.4);
		}
		form input:focus {
		  background-color: white;
		  width: 300px;
		  color: #53e3a6;
		}
		form button {
		  -webkit-appearance: none;
		     -moz-appearance: none;
		          appearance: none;
		  outline: 0;
		  background-color: white;
		  border: 0;
		  padding: 10px 15px;
		  color: #53e3a6;
		  border-radius: 3px;
		  width: 125px;
		  cursor: pointer;
		  font-size: 18px;
		  -webkit-transition-duration: 0.25s;
		          transition-duration: 0.25s;
		}
		form button:hover {
		  background-color: #f5f7f9;
		}
		.bg-bubbles {
		  position: absolute;
		  top: 0;
		  left: 0;
		  width: 100%;
		  height: 100%;
		  z-index: 1;
		}
		.bg-bubbles li {
		  position: absolute;
		  list-style: none;
		  display: block;
		  width: 40px;
		  height: 40px;
		  background-color: rgba(255, 255, 255, 0.15);
		  bottom: -160px;
		  -webkit-animation: square 25s infinite;
		  animation: square 25s infinite;
		  -webkit-transition-timing-function: linear;
		  transition-timing-function: linear;
		}
		.bg-bubbles li:nth-child(1) {
		  left: 10%;
		}
		.bg-bubbles li:nth-child(2) {
		  left: 20%;
		  width: 80px;
		  height: 80px;
		  -webkit-animation-delay: 2s;
		          animation-delay: 2s;
		  -webkit-animation-duration: 17s;
		          animation-duration: 17s;
		}
		.bg-bubbles li:nth-child(3) {
		  left: 25%;
		  -webkit-animation-delay: 4s;
		          animation-delay: 4s;
		}
		.bg-bubbles li:nth-child(4) {
		  left: 40%;
		  width: 60px;
		  height: 60px;
		  -webkit-animation-duration: 22s;
		          animation-duration: 22s;
		  background-color: rgba(255, 255, 255, 0.25);
		}
		.bg-bubbles li:nth-child(5) {
		  left: 70%;
		}
		.bg-bubbles li:nth-child(6) {
		  left: 80%;
		  width: 120px;
		  height: 120px;
		  -webkit-animation-delay: 3s;
		          animation-delay: 3s;
		  background-color: rgba(255, 255, 255, 0.2);
		}
		.bg-bubbles li:nth-child(7) {
		  left: 32%;
		  width: 160px;
		  height: 160px;
		  -webkit-animation-delay: 7s;
		          animation-delay: 7s;
		}
		.bg-bubbles li:nth-child(8) {
		  left: 55%;
		  width: 20px;
		  height: 20px;
		  -webkit-animation-delay: 15s;
		          animation-delay: 15s;
		  -webkit-animation-duration: 40s;
		          animation-duration: 40s;
		}
		.bg-bubbles li:nth-child(9) {
		  left: 25%;
		  width: 10px;
		  height: 10px;
		  -webkit-animation-delay: 2s;
		          animation-delay: 2s;
		  -webkit-animation-duration: 40s;
		          animation-duration: 40s;
		  background-color: rgba(255, 255, 255, 0.3);
		}
		.bg-bubbles li:nth-child(10) {
		  left: 90%;
		  width: 160px;
		  height: 160px;
		  -webkit-animation-delay: 11s;
		          animation-delay: 11s;
		}
		@-webkit-keyframes square {
		  0% {
		    -webkit-transform: translateY(0);
		            transform: translateY(0);
		  }
		  100% {
		    -webkit-transform: translateY(-700px) rotate(600deg);
		            transform: translateY(-700px) rotate(600deg);
		  }
		}
		@keyframes square {
		  0% {
		    -webkit-transform: translateY(0);
		            transform: translateY(0);
		  }
		  100% {
		    -webkit-transform: translateY(-700px) rotate(600deg);
		            transform: translateY(-700px) rotate(600deg);
		  }
		}
		.cc{
			text-decoration: none;
			color: #53e3a6; 
			}
	</style>
	<script type="text/javascript">
		
		 $("#login-button").click(function(event){
				 event.preventDefault();
			 
			 $('form').fadeOut(500);
			 $('.wrapper').addClass('form-success');
		});
		function check(){
	    {
		  if(form.username.value == "")//如果用户名为空
		  {
			alert("您还没有填写用户名!");
			form.username.focus();
			return false;
		  }
		  if(form.password.value == "")//如果密码为空
		  {
			alert("您还没有填写密码!");
			myform.password.focus();
			return false;
		  }
		}
		
		
	</script>
</head>
<body>
	<div class="wrapper">
		<div class="container">
			<h1>Welcome</h1>
			
			<form name='form' class="form" method='post' action='login.php' onSubmit="return check()">
				<input type="text" placeholder="Username" name='username'>
				<input type="password" placeholder="Password" name='password'>
				<button type="submit" id="login-button" name='submit' value='submit'>Login</button>
			</form>
		</div>
		
		<ul class="bg-bubbles">
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
			<li></li>
		</ul>
	</div>
</body>
</html>

PHP文件

<?php 
$username=$_POST['username'];
$password=$_POST['password'];
$link = mysqli_connect('127.0.0.1','root','123456','vultureData');
$query=mysqli_query($link,"SELECT username,password FROM webuserinfo WHERE username = '$username'");//找到与输入用户名相同的信息,注意要取出的信息有两项
$row = mysqli_fetch_array($query);
if($_POST['submit']){    
    if($row['username']==$username &&$row['password']==$password){
        //setcookie('uname',$username,time()+7200);
        echo "<script>alert('successfully');window.location= 'index.php';</script>";
    }
    else echo "<script>alert('failed');history.go(-1)</script>";//返回之前的页面
}
include('login.html');?>

  • 45
    点赞
  • 253
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
Streamlit是一个用于构建数据科学和机器学习应用程序的Python库。它提供了一个简单易用的界面,可以快速创建交互式的Web应用程序。然而,Streamlit本身并不提供直接的登录界面功能,但你可以使用其他库或框架来实现登录功能,并将其与Streamlit集成在一起。 一种常见的做法是使用Flask作为后端框架来处理用户认证和登录逻辑。你可以使用Flask的登录扩展,如Flask-Login或Flask-User,来管理用户的登录状态和权限控制。这些扩展提供了一些方便的功能,如用户注册、登录、注销等。 在Streamlit应用程序中,你可以使用Flask的路由功能来定义不同的页面和视图函数。例如,你可以创建一个登录页面的路由,并在该路由上渲染一个HTML模板,包含用户名和密码输入框以及登录按钮。当用户点击登录按钮时,你可以通过Flask的认证机制验证用户输入的用户名和密码是否正确,并根据验证结果进行相应的处理。 以下是一个简单的示例代码,演示了如何在Streamlit应用程序中实现一个基本的登录界面: ```python import streamlit as st from flask import Flask, render_template, request from flask_login import LoginManager, UserMixin, login_user, logout_user, login_required # 创建Flask应用程序 app = Flask(__name__) app.secret_key = 'your_secret_key' # 创建LoginManager对象 login_manager = LoginManager() login_manager.init_app(app) # 创建一个简单的用户类 class User(UserMixin): def __init__(self, username): self.username = username # 用户认证回调函数 @login_manager.user_loader def load_user(user_id): # 这里可以根据user_id从数据库或其他存储中获取用户信息 return User(user_id) # 登录页面路由 @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] # 这里可以根据用户名和密码进行验证 if username == 'admin' and password == 'password': user = User(username) login_user(user) return '登录成功!' else: return '用户名或密码错误!' return render_template('login.html') # 保护页面的路由 @app.route('/protected') @login_required def protected(): return '这是一个受保护的页面,只有登录用户才能访问!' # 注销路由 @app.route('/logout') @login_required def logout(): logout_user() return '注销成功!' # Streamlit应用程序 def main(): st.title('登录示例') st.write('请访问以下链接进行登录:') st.write('[登录](http://localhost:5000/login)') st.write('[受保护页面](http://localhost:5000/protected)') st.write('[注销](http://localhost:5000/logout)') if __name__ == '__main__': main() ``` 在上述示例中,我们使用Flask-Login来处理用户认证和登录逻辑。在登录页面的路由中,我们通过`request.form`获取用户输入的用户名和密码,并进行验证。如果验证通过,我们创建一个`User`对象,并使用`login_user`函数将用户登录状态保存在会话中。在受保护页面的路由中,我们使用`@login_required`装饰器来限制只有登录用户才能访问该页面。在注销路由中,我们使用`logout_user`函数将用户的登录状态从会话中移除。 请注意,上述示例仅提供了一个基本的登录界面实现思路,并没有涉及到真实的数据库或密码加密等安全性考虑。在实际应用中,你需要根据具体需求和安全性要求进行适当的改进和扩展。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值