前端部分代码实现

 <div id="mainCp">
<div class="postForm">
<p>
<label>用户账号:</label>
<input name="oldpwd" type="text" id="username" class="intxt" />
</p>
<p class="cellBg">
<label>用户密码:</label>
<input name="userpwd" type="password" id="userpwd" class="intxt" />
<span id="_userpwdok"></span>
</p>
<p class="cellBg">
<label>重复密码:</label>
<input name="userpwd" type="password" id="reuserpwd" class="intxt" />
<span id="_userpwdok"></span>
</p> <p class="cellBg">
<label>验证码号:</label>
<input name="vdcode" type="text" id="vdcode" class="intxt" />
<img id="code" src="" align="absmiddle" alt="看不清?点击更换" style="cursor:pointer;" onclick="getCode()">
</p> <p>
<button class="button2" type="button" id="login">登录账号</button>
<button class="button2 ml10" type="reset">重新填写</button>
</p>
</div>
</div>
 <style>
#out{
position: fixed;
top:0;
left:0;
z-index: 10000;
background: rgba(0,0,0,0.7);
display:flex;
align-items: center;
justify-content: center;
overflow: hidden;
width:0px;
height:0px;
}
#in{
margin: 200px auto;
width:300px;
height:100px;
display:flex;
align-items: center;
justify-content: center;
background:#fff;
border-radius: 14px;
font-size: 16px;
font-weight: bold;
}
</style>
<div id="out">
<div id="in"></div>
</div>
<script src="http://libs.baidu.com/jquery/2.1.1/jquery.min.js"></script>
<script src="/public/static/js/StrPlay.class.js"></script>
<script src="/public/static/js/Ele.class.js"></script>
<script src="/public/static/js/loginCheck.js"></script>
<script>
// ------ 获取验证码
function getCode() {
var imgCode = find('#code');
imgCode.src = 'http://0609.cn/Config/image/imgcode.php?num=6&y=34&x=150' + "&time=" + new Date().getTime();
}
// ------ 初始化
function init() {
loop("input",function(item) {
item.value = "";
})
}
// ------ 遍历输入框
function loop(str,fn) {
find(str).forEach((item,index)=> {
fn(item);
});
}
// ------ 代码运行时长
function runLen(fn) {
window.addEventListener('load',function(){
console.group("程序运行时长:");
console.time();
fn();
console.timeEnd();
console.groupEnd();
});
}
// ------ 输入检测
function inputCheck(e) {
e.username('username');
e.password('userpwd');
e.repassword('reuserpwd','userpwd');
}
// ------ 点击登录,获取表单信息,检查数据是否合格,请求服务端检测程序
function goLogin() {
show("正在处理,请稍后 . . . .");
var param = {};
param.username = find('#username').value;
param.password = find('#userpwd').value;
param.code = find('#vdcode').value;
$.post('http://0609.cn/public/index.php/check',param,function(data) {
data = data.split(",").map(item => {
return item.split("=>");
})
let mdata = new Map(data);
find('#in').innerHTML = mdata.get('login');
});
}
// ------ DOM效果展示
function show(tip) {
var pageWidth = window.innerWidth;
var pageHeight = window.innerHeight;
if (typeof pageWidth != "number"){
if (document.compatMode == "CSS1Compat"){
pageWidth = document.documentElement.clientWidth;
pageHeight = document.documentElement.clientHeight;
} else {
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
}
}
find('#out').style.cssText = "display:block;width:" + pageWidth + "px;height:" + pageHeight +"px";
find('#in').innerHTML = tip;
find('#out').addEventListener("click",function(){
find('#out').style.cssText = "display:none;";
},true);
}
// ------ 通过选择器,获取DOM元素
function find(str) {
return str.charAt(0) === "#" ?
document.querySelector(str) : document.querySelectorAll(str);
}
// ------ 错误异常检测
function errorCheck() {
window.addEventListener('error',function(error){
if(error.filename){return false;}else{
console.log(error.target+"资源加载失败"+":");
console.log(error.target);}
},true);
window.onerror = function(message, source, lineno, colno, error) {
console.log("程序运行出错:"+message+" at "+lineno+":"+colno);
return true;
}
window.addEventListener('unhandledrejection',function(event){
event && event.preventDefault();
console.log("数据接口请求失败");
},true);
} // ------ 开始运行程序
runLen(function() {
var e = new Check();
init();
inputCheck(e);
getCode();
loop("input",function(item){
item.addEventListener('blur',function() {
if(!Object.values(e.fit).includes(false)){
find('#login').addEventListener('click',goLogin,true);
}else{
find('#login').removeEventListener('click',goLogin,true);
}
},true);
});
errorCheck();
}); </script>

服务端代码实现

 namespace app\index\controller;
use app\index\model\Data as MD;
class Checklogin
{
public function __construct()
{
// parent::__construct();
}
public function check()
{
header('Content-type:text/html;charset=utf-8;');
$code=strtolower($this->checkcode());
$username=$this->userlist()->username;
$password=$this->userlist()->password;
sleep(3);
if($_REQUEST['code'] != $code)
{
echo "login=>验证码错误";
exit;
}
if($_REQUEST['username'] != $username)
{
echo "login=>用户名或密码错误";
exit;
}
if($_REQUEST['password'] != $password)
{
echo "login=>用户名或密码错误";
exit;
}
$str="";
foreach($this->userlist() as $k=>$v){
$str .= $k."=>".$v.",";
}
echo $str."login=>登录成功";
exit;
}
public function checkcode(){
session_start();
return $_SESSION['code'];
}
public function userlist(){
$user = new \stdClass();
$user->username = "username";
$user->password = "123456";
$user->name = "Tom json";
$user->age = "50";
$user->sex = "man";
$user->vip = "是";
return $user;
}
}

session + cookie 实现登录功能的更多相关文章

  1. Django框架之cookie和session及开发登录功能

    1.cookie是什么? Web应用程序是使用HTTP协议传输数据的.HTTP协议是无状态的协议.一旦数据交换完毕,客户端与服务器端的连接就会关闭,再次交换数据需要建立新的连接.这就意味着服务器无法从 ...

  2. 步步为营-76-用户登录(Session+Cookie)

    说明:cookie是保存在浏览器的.Session是存储在服务器的 1 同样UI页面还是web前端提供 1.1 首先,经过验证码校验:将系统产生的验证码放入到Session中,然后取Session值注 ...

  3. session、cookie 记住登录状态的实现

    Cookie的机制 Cookie是浏览器(User Agent)访问一些网站后,这些网站存放在客户端的一组数据,用于使网站等跟踪用户,实现用户自定义功能. Cookie的Domain和Path属性标识 ...

  4. 自己Cookie写的自动登录功能 包含BASE64 和MD5的使用

    sql表 username  password字段 User类 有 id username password等字段 Service有一函数 @Override public User findUser ...

  5. cookie理解与实践【实现简单登录以及自动登录功能】

    cookie理解 Cookie是由W3C组织提出,最早由netscape社区发展的一种机制 http是无状态协议.当某次连接中数据提交完,连接会关闭,再次访问时,浏览器与服务器需要重新建立新的连接: ...

  6. 在基于vue的webpack脚手架开发中使用了代理转发,结果浏览器发出的请求中不带cookie导致登录时总是session失效怎么办?

    环境:            有2个业务接口需要转发到82的服务器上:     ../user/getCode.do     ../user/doLogin.do 现象:          使用上述的 ...

  7. 使用COOKIE实现登录 VS 使用SESSION实现登录

    注:本文使用的代码基于PHP,其他语言逻辑同理. 一:使用COOKIE实现登录验证 使用cookie实现登录的方式,主要通过一些单向的加密信息进行验证.比如admin用户登录了之后,服务端生成一个co ...

  8. 完成登录功能,用session记住用户名

    登录功能完成: js:设置return html:设置 form input py: @app.route设置methods GET POST 读取表单数据 查询数据库 用户名密码对: 记住用户名 跳 ...

  9. 通过jquery.cookie.js实现记住用户名、密码登录功能

    Cookies 定义:让网站服务器把少量数据储存到客户端的硬盘或内存,从客户端的硬盘读取数据的一种技术: 下载与引入:jquery.cookie.js基于jquery:先引入jquery,再引入:jq ...

随机推荐

  1. centos 7 c++连接mysql的常用函数说明及使用样例

    以下函数使用之前需安装mysql,并包含mysql.h头文件,设置好mysqlclient动态库 一.mysql_init() MYSQL * mysql_init(MYSQL *mysql); // ...

  2. 64位手机无法加载x5(libmttwebview.so is 32-bit instead of 64-bit)

    x5内核暂时不提供64位的so文件,在64位手机上需要让AP以32位模式运行. 具体操作如下: 1.如果使用是Eclipse则需要将所有的.so文件都放置在so加载目录:lib/armeabi文件夹下 ...

  3. CGAL 获取相关功能的依赖头文件

    CGAL 获取相关功能的依赖头文件 由于CGAL是header include only.只需要头文件就可以实现相关的功能.有时候为了实现一个简单的功能, 在研究具体实现的时候能够知道这个功能对应的头 ...

  4. 安装 KubeSphere DevOps 系统

    1.  安装KubeSphere 安装了一夜,终于看到了期待已久的画面 第一步.硬件配置(PS:VirtualBox虚拟机): 操作系统:Ubuntu 18.04 CPU:4核 内存:8G 磁盘:60 ...

  5. Redis的持久化设计

    Redis 持久化设计 持久化的功能:Redis是内存数据库,数据都是存储在内存中的,为了避免进程退出导致数据的永久丢失,要定期将Redis中的数据以某种形式从内存保存到硬盘,当下次Reids重启时, ...

  6. 049.Kubernetes集群管理-集群监控Metrics

    一 集群监控 1.1 Metrics Kubernetes的早期版本依靠Heapster来实现完整的性能数据采集和监控功能,Kubernetes从1.8版本开始,性能数据开始以Metrics API的 ...

  7. 这一次搞懂Spring事务注解的解析

    前言 事务我们都知道是什么,而Spring事务就是在数据库之上利用AOP提供声明式事务和编程式事务帮助我们简化开发,解耦业务逻辑和系统逻辑.但是Spring事务原理是怎样?事务在方法间是如何传播的?为 ...

  8. 漏洞复现-Office远程代码执行漏洞 (CVE-2017-11882&CVE-2018-0802)

    漏洞原理 这两个漏洞本质都是由Office默认安装的公式编辑器(EQNEDT32.EXE)引发的栈溢出漏洞(不要问什么是栈溢出,咱也解释不了/(ㄒoㄒ)/~~) 影响版本 Office 365 Mic ...

  9. js中each函数的用法

    官方说明: jQuery.each(object, [callback]) 概述 通用例遍方法,可用于例遍对象和数组. 不同于例遍 jQuery 对象的 $().each() 方法,此方法可用于例遍任 ...

  10. 从Spring Initializr开始

    出识springcloud我们这里需要建立两个项目 来感受下微服务 一.配置服务 1. Spring Initializr. 用idea自带的 Spring Initializr. 建立第一个项目 2 ...