php
<code><?php session_start(); include ('conn.php'); $action = $_GET['action']; if ($action == 'login') { //登录 $email = $_POST['email']; $pass = $_POST['password']; if (empty ($email)) { echo '邮箱不能为空'; exit; } if (empty ($pass)) { echo '密码不能为空'; exit; } // $md5pass = md5($password); $query = mysql_query("select * from user where email='$email'"); $us = is_array($row = mysql_fetch_array($query)); $ps = $us ? $pass == $row['password'] : FALSE; if ($ps) { $counts = $row['login_counts'] + 1; $_SESSION['email'] = $row['email']; $_SESSION['login_time'] = $row['login_time']; $_SESSION['login_counts'] = $counts; $ip = get_client_ip(); $logintime = mktime(); $rs = mysql_query("update user set login_time='$logintime',login_ip='$ip',login_counts='$counts'"); if ($rs) { echo '1';exit; $arr['success'] = 1; $arr['msg'] = '登录成功!'; $arr['email'] = $_SESSION['email']; $arr['login_time'] = date('Y-m-d H:i:s',$_SESSION['login_time']); $arr['login_counts'] = $_SESSION['login_counts']; } else { $arr['success'] = 0; $arr['msg'] = '登录失败'; } } else { $arr['success'] = 0; $arr['msg'] = '用户名或密码错误!'; } echo json_encode($arr); } elseif ($action == 'logout') { //退出 unset($_SESSION); session_destroy(); echo '1'; } ``` js ``` // JavaScript Document $(function(){ $("#email").focus(); $("input:text,textarea,input:password").focus(function() { $(this).addClass("cur_select"); }); $("input:text,textarea,input:password").blur(function() { $(this).removeClass("cur_select"); }); $("#btn-login").bind('click',function(){ var email = $("#email").val(); var password = $("#password").val(); if(email==""){ $(".control-group-email").removeClass('has-success').addClass("has-error"); $('<div class="help-block-text">').text("邮箱不能为空!").appendTo($('.control-group-email')); $("#email").focus(); return false; }else{ $(".control-group-email").removeClass("has-error").addClass("has-success") $('.help-block-text').remove(); $("#password").focus(); } if(password==""){ $(".control-group-password").removeClass("has-success").addClass("has-error"); $('<div class="help-block-text"></div>').text("密码不为空!").appendTo($('.control-group-password')); $("#password").focus(); return false; }else{ $(".control-group-password").removeClass("has-error").addClass("has-success") $('.help-block-text').remove(); $("#btn-login").focus(); } $.ajax({ type: "POST", url: "login.php?action=login", dataType: "json", data: {"email":email,"password":password}, beforeSend: function(){ $('<div id="msg"></div>').addClass("loading").html("正在登录...").css("color","#999").appendTo('#btn-login').fadeOut(1000 ); }, success: function(json){ if(json.success==1){ $("#login-form").remove(); var div = "<div id="result"> <p><strong>"+json.email+"</strong>,恭喜您登录成功!</p> <p>您这是第<span>"+json.login_counts+ "</span>次登录本站。</p> <p>上次登录本站的时间是:<span>"+json.login_time+ "</span></p> <p><a href="#" id="logout">【退出】</a></p> </div>"; $("#login").append($('div')); }else{ // $("#msg").remove(); $('<div id="errmsg"></div>').html(json.msg).css("color","#999").appendTo('.help-block').fadeOut(2000); return false; } } }); }); $("#logout").bind('click',function(){ $.post("login.php?action=logout",function(msg){ if(msg==1){ $("#result").remove(); var div = '<div id="login-form"> <div class="control-group-email"> <label class="control-label">邮箱</label> <input type="email" class="form-control" name="email" id="email" placeholder="请输入可用的邮箱地址"> </div> <div class="control-group-password"> <label class="control-label">密码</label> <input type="password" class="form-control" name="password" id="password"> </div> <span id="helpBlock" class="help-block">没有帐号<a href="register.php">点击这里</a></span><button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><span class="fa fa-weibo" aria-hidden="true"></span></button><button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><span class="fa fa-weixin" aria-hidden="true"></span></button><button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"><span class="fa fa-qq" aria-hidden="true"></span></button><div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button><button type="submit" class="btn btn-primary" id="btn-login">登录</button> </div> </div>'; $("#login").append(div); } }); }); }); ``` index.php ``` <div id="login"> <?php if(isset($_SESSION['email'])){ ?> <div id="result"> <p><strong><?php echo $_SESSION['email'];?></strong>,恭喜您登录成功!</p> <p>您这是第<span><?php echo $_SESSION['login_counts'];?></span>次登录本站。</p> <p>上次登陆本站的时间是:<span><?php echo date('Y-m-d H:i:s',$_SESSION['login_time']);?> </span></p> <p><a href="#" id="logout">【退出】</a></p> </div> <?php }else{?> <div id="login-form"> <div class="control-group-email"> <label class="control-label">邮箱</label> <input type="email" class="form-control" name="email" id="email" placeholder="请输入可用的邮箱地址"> </div> <div class="control-group-password"> <label class="control-label">密码</label> <input type="password" class="form-control" name="password" id="password"> </div> <span id="helpBlock" class="help-block">没有帐号<a href="register.php">点击这里</a></span> <button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"> <span class="fa fa-weibo" aria-hidden="true"></span></button> <button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"> <span class="fa fa-weixin" aria-hidden="true"></span></button> <button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal"> <span class="fa fa-qq" aria-hidden="true"></span></button> <div class="modal-footer"> <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button> <button type="submit" class="btn btn-primary" id="btn-login">登录</button> </div> <?php } ?> </div> <h2 id="回复内容">回复内容:</h2> <p>php</p> <pre class="brush:php;toolbar:false"><code><?php session_start(); include ('conn.php'); $action = $_GET['action']; if ($action == 'login') { //登录 $email = $_POST['email']; $pass = $_POST['password']; if (empty ($email)) { echo '邮箱不能为空'; exit; } if (empty ($pass)) { echo '密码不能为空'; exit; } // $md5pass = md5($password); $query = mysql_query("select * from user where email='$email'"); $us = is_array($row = mysql_fetch_array($query)); $ps = $us ? $pass == $row['password'] : FALSE; if ($ps) { $counts = $row['login_counts'] + 1; $_SESSION['email'] = $row['email']; $_SESSION['login_time'] = $row['login_time']; $_SESSION['login_counts'] = $counts; $ip = get_client_ip(); $logintime = mktime(); $rs = mysql_query("update user set login_time='$logintime',login_ip='$ip',login_counts='$counts'"); if ($rs) { echo '1';exit; $arr['success'] = 1; $arr['msg'] = '登录成功!'; $arr['email'] = $_SESSION['email']; $arr['login_time'] = date('Y-m-d H:i:s',$_SESSION['login_time']); $arr['login_counts'] = $_SESSION['login_counts']; } else { $arr['success'] = 0; $arr['msg'] = '登录失败'; } } else { $arr['success'] = 0; $arr['msg'] = '用户名或密码错误!'; } echo json_encode($arr); } elseif ($action == 'logout') { //退出 unset($_SESSION); session_destroy(); echo '1'; } ``` js ``` // JavaScript Document $(function(){ $("#email").focus(); $("input:text,textarea,input:password").focus(function() { $(this).addClass("cur_select"); }); $("input:text,textarea,input:password").blur(function() { $(this).removeClass("cur_select"); }); $("#btn-login").bind('click',function(){ var email = $("#email").val(); var password = $("#password").val(); if(email==""){ $(".control-group-email").removeClass('has-success').addClass("has-error"); $('<div class="help-block-text"></code>

The article explains how to create, implement, and use interfaces in PHP, focusing on their benefits for code organization and maintainability.

The article discusses the differences between crypt() and password_hash() in PHP for password hashing, focusing on their implementation, security, and suitability for modern web applications.

Article discusses preventing Cross-Site Scripting (XSS) in PHP through input validation, output encoding, and using tools like OWASP ESAPI and HTML Purifier.

Autoloading in PHP automatically loads class files when needed, improving performance by reducing memory use and enhancing code organization. Best practices include using PSR-4 and organizing code effectively.

PHP streams unify handling of resources like files, network sockets, and compression formats via a consistent API, abstracting complexity and enhancing code flexibility and efficiency.

The article discusses managing file upload sizes in PHP, focusing on the default limit of 2MB and how to increase it by modifying php.ini settings.

The article discusses nullable types in PHP, introduced in PHP 7.1, allowing variables or parameters to be either a specified type or null. It highlights benefits like improved readability, type safety, and explicit intent, and explains how to declar

The article discusses the differences between unset() and unlink() functions in programming, focusing on their purposes and use cases. Unset() removes variables from memory, while unlink() deletes files from the filesystem. Both are crucial for effec


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
