日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > 数据库 >内容正文

数据库

PHP+MySQL+JavaScript实现注册登录(防黑客爆破)

發布時間:2023/12/29 数据库 29 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PHP+MySQL+JavaScript实现注册登录(防黑客爆破) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

注冊界面html前端

<!DOCTYPE html> <html><head><meta charset="utf-8"><title></title></head><body>注冊界面<form action="./login.php" method="post"> <!--加載連接數據庫的php文件,提交方式post --><input type="text" name="user" id="" value="" /><input type="password" name="pass" id="" value="" /><input type="submit" name="" id="" value="" /></form></body> </html> <!--作者:871535144@qq.com時間:2019-06-03描述:簡單注冊界面 -->

登錄界面html前端

<!DOCTYPE html> <html><head><meta charset="utf-8"><title></title></head><body>登陸界面一.30分鐘以內只能錯5次二.一個ip只能在30分鐘內錯5次<form action="./land.php" method="post"> <!--加載連接數據庫的php文件,提交方式post --><input type="text" name="user" id="" value="" /><input type="password" name="pass" id="" value="" /><input type="submit" name="" id="" value="" /></form></body> </html> <!--作者:871535144@qq.com時間:2019-06-03描述:簡單注冊界面 -->

連接數據庫php文件

<?php $host='127.0.0.1'; //數據庫地址 $sqlname='root'; //數據庫賬號 $sqlpass='123456'; //數據庫密碼 $sqldb='login'; //數據庫名 $con = mysql_connect($host,$sqlname,$sqlpass); //連接數據庫 mysql_select_db($sqldb); //選擇數據庫 mysql_query("set names 'utf8'"); //設置編碼格式 ?><!--作者:871535144@qq.com時間:2019-06-03描述:php連接數據庫 -->

注冊php文件

<?php require_once("./conn.php"); header('Content-Type:text/html;charset=utf-8'); @$user=$_POST['user']; @$pass=$_POST['pass']; $cxname="select * from user where name='$user'"; $zhix=mysql_query($cxname); $row = mysql_fetch_array($zhix); if (!isset($user) || empty($user) ) {echo '<script> if (confirm("你的賬號為空")) {  window.location.href="login.html";} else {  window.location.href="login.html"; } </script>'; } else if(!isset($pass) || empty($pass) ) {echo '<script> if (confirm("你的密碼為空")) {  window.location.href="login.html";} else {  window.location.href="login.html"; } </script>'; } else if($row){echo '<script> if (confirm("用戶名已存在")) {  window.location.href="login.html";} else {  window.location.href="login.html"; } </script>'; } else{@$pass=md5($pass); //密碼MD5加密$login="insert into user(name,password) values('$user','$pass')"; //MySQL插入語句if (mysql_query($login)){ //判斷命令是否執行成功$tianjia2="update user set cishu=0 where name='$user'";$tianjia3=mysql_query($tianjia2);echo '<script> if (confirm("注冊成功")) {  window.location.href="land.html";} else {  window.location.href="land.html"; } </script>';}else{echo $login;echo '<script> if (confirm("注冊失敗")) {  window.location.href="login.html";} else {  window.location.href="login.html"; } </script>';} } ?> <!--作者:871535144@qq.com時間:2019-06-03描述:插入數據庫 -->

獲取ip php文件

<?phpif(getenv('HTTP_CLIENT_IP')) {$onlineip = getenv('HTTP_CLIENT_IP'); } elseif(getenv('HTTP_X_FORWARDED_FOR')) {$onlineip = getenv('HTTP_X_FORWARDED_FOR'); } elseif(getenv('REMOTE_ADDR')) {$onlineip = getenv('REMOTE_ADDR'); } else {$onlineip = $HTTP_SERVER_VARS['REMOTE_ADDR']; } ?>

登錄驗證php文件

<?php header('Content-Type:text/html;charset=utf-8'); require_once("./conn.php"); //獲取ip接口 require_once("./ip.php"); //開啟緩存 session_start(); @$ip=addslashes($onlineip); @$user=addslashes($_POST['user']); @$pass=md5($_POST['pass']); @$gettime=date('Y-m-d H:i:s');//獲取當前時間 @$xtime=date("Y-m-d H:i:s",time()+8*60*60+30*60);//從php5.1.0開始,php.ini里加了date.timezone這個選項,并且默認情況都是格林威治標準時間和北京時間差了正好8個小時。 @$time=date("Y-m-d H:i:s",time()+8*60*60); $cxlogin="select * from user where name='$user'"; $zxcxlogin=mysql_query($cxlogin); $cxloginsz=mysql_fetch_array($zxcxlogin);//用戶信息 $tjtime="update user set time='$xtime' where name='$user'"; //時間 $tjnumber="update user set cishu=cishu+1 where name='$user'";//次數+1 $cls="update user set cishu=0 where name='$user'";//清除次數 $tjip="update user set ip='$ip' where name='$user'";//ip//錯誤次數小于5次 if($cxloginsz['cishu']<5){//檢測賬號和密碼$cxpassword="select * from user where name='$user' and password='$pass' ";$zhix=mysql_query($cxpassword);$row = mysql_fetch_array($zhix);if($row){$tianjia1=mysql_query($cls);echo '<script> if (confirm("登錄成功")) {  window.location.href="hellosmile.html";} else {  window.location.href="hellosmile.html"; } </script>';}else{$tianjia2=mysql_query($tjtime);$tianjia3=mysql_query($tjnumber);$tianjia4=mysql_query($tjip);echo '<script> if (confirm("登錄失敗,切記不能連續錯5次")) {  window.location.href="land.html";} else {  window.location.href="land.html"; } </script>';}};//錯誤次數大于5次且時間不到 if($cxloginsz['cishu']>=5 && strtotime($cxloginsz['time'])>strtotime($time)){echo '<script> if (confirm("賬號已凍結請在30分鐘后登陸")) {  window.location.href="land.html";} else {  window.location.href="land.html"; } </script>'; };//時間到了 if($cxloginsz['cishu']>=5 && strtotime($cxloginsz['time'])<strtotime($time)){ $tianjia1=mysql_query($cls); $tianjia2=mysql_query($tjtime); $cxpassword="select * from user where name='$user' and password='$pass' "; $zhix=mysql_query($cxpassword); $row = mysql_fetch_array($zhix); if($row){echo '<script> if (confirm("登錄成功")) {  window.location.href="hellosmile.html";} else {  window.location.href="hellosmile.html"; } </script>'; }else{ $tianjia3=mysql_query($tjnumber); $tianjia4=mysql_query($tjip); echo '<script> if (confirm("解凍時間到了")) {  window.location.href="land.html";} else {  window.location.href="land.html"; } </script>'; } };if($cxloginsz['ip']=='$ip'){$tianjia1=mysql_query($cls); $tianjia2=mysql_query($tjtime); $cxpassword="select * from user where name='$user' and password='$pass' "; $zhix=mysql_query($cxpassword); $row = mysql_fetch_array($zhix); if($row){echo '<script> if (confirm("登錄成功")) {  window.location.href="hellosmile.html";} else {  window.location.href="hellosmile.html"; } </script>'; }else{ $tianjia3=mysql_query($tjnumber); $tianjia4=mysql_query($tjip); echo '<script> if (confirm("解凍時間到了")) {  window.location.href="land.html";} else {  window.location.href="land.html"; } </script>'; } };?>

成功登錄跳轉頁面html代碼

<!DOCTYPE html> <html lang="zh"> <head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta http-equiv="X-UA-Compatible" content="ie=edge" /><title>Document</title> </head> <body><div>跳轉頁面</br>hellosmile</div> </body> </html>

數據庫結構

time為登錄時間+30分鐘;cishu是錯誤次數

實現功能:

注冊頁面:(判斷用戶是否存在),數據庫中添加用戶
登錄頁面: 判斷是否連續錯誤5次,連續錯誤5次后需等待30分鐘解凍 賬號,若改換ip后將重新獲取5次機會

總結

以上是生活随笔為你收集整理的PHP+MySQL+JavaScript实现注册登录(防黑客爆破)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。