PHP+MySQL+JavaScript实现注册登录(防黑客爆破)
生活随笔
收集整理的這篇文章主要介紹了
PHP+MySQL+JavaScript实现注册登录(防黑客爆破)
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
注冊(cè)界面html前端
<!DOCTYPE html> <html><head><meta charset="utf-8"><title></title></head><body>注冊(cè)界面<form action="./login.php" method="post"> <!--加載連接數(shù)據(jù)庫的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時(shí)間:2019-06-03描述:簡(jiǎn)單注冊(cè)界面 -->登錄界面html前端
<!DOCTYPE html> <html><head><meta charset="utf-8"><title></title></head><body>登陸界面一.30分鐘以內(nèi)只能錯(cuò)5次二.一個(gè)ip只能在30分鐘內(nèi)錯(cuò)5次<form action="./land.php" method="post"> <!--加載連接數(shù)據(jù)庫的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時(shí)間:2019-06-03描述:簡(jiǎn)單注冊(cè)界面 -->連接數(shù)據(jù)庫php文件
<?php $host='127.0.0.1'; //數(shù)據(jù)庫地址 $sqlname='root'; //數(shù)據(jù)庫賬號(hào) $sqlpass='123456'; //數(shù)據(jù)庫密碼 $sqldb='login'; //數(shù)據(jù)庫名 $con = mysql_connect($host,$sqlname,$sqlpass); //連接數(shù)據(jù)庫 mysql_select_db($sqldb); //選擇數(shù)據(jù)庫 mysql_query("set names 'utf8'"); //設(shè)置編碼格式 ?><!--作者:871535144@qq.com時(shí)間:2019-06-03描述:php連接數(shù)據(jù)庫 -->注冊(cè)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("你的賬號(hào)為空")) { 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)){ //判斷命令是否執(zhí)行成功$tianjia2="update user set cishu=0 where name='$user'";$tianjia3=mysql_query($tianjia2);echo '<script> if (confirm("注冊(cè)成功")) { window.location.href="land.html";} else { window.location.href="land.html"; } </script>';}else{echo $login;echo '<script> if (confirm("注冊(cè)失敗")) { window.location.href="login.html";} else { window.location.href="login.html"; } </script>';} } ?> <!--作者:871535144@qq.com時(shí)間:2019-06-03描述:插入數(shù)據(jù)庫 -->獲取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']; } ?>登錄驗(yàn)證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');//獲取當(dāng)前時(shí)間 @$xtime=date("Y-m-d H:i:s",time()+8*60*60+30*60);//從php5.1.0開始,php.ini里加了date.timezone這個(gè)選項(xiàng),并且默認(rèn)情況都是格林威治標(biāo)準(zhǔn)時(shí)間和北京時(shí)間差了正好8個(gè)小時(shí)。 @$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'"; //時(shí)間 $tjnumber="update user set cishu=cishu+1 where name='$user'";//次數(shù)+1 $cls="update user set cishu=0 where name='$user'";//清除次數(shù) $tjip="update user set ip='$ip' where name='$user'";//ip//錯(cuò)誤次數(shù)小于5次 if($cxloginsz['cishu']<5){//檢測(cè)賬號(hào)和密碼$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("登錄失敗,切記不能連續(xù)錯(cuò)5次")) { window.location.href="land.html";} else { window.location.href="land.html"; } </script>';}};//錯(cuò)誤次數(shù)大于5次且時(shí)間不到 if($cxloginsz['cishu']>=5 && strtotime($cxloginsz['time'])>strtotime($time)){echo '<script> if (confirm("賬號(hào)已凍結(jié)請(qǐng)?jiān)?0分鐘后登陸")) { window.location.href="land.html";} else { window.location.href="land.html"; } </script>'; };//時(shí)間到了 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("解凍時(shí)間到了")) { 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("解凍時(shí)間到了")) { window.location.href="land.html";} else { window.location.href="land.html"; } </script>'; } };?>成功登錄跳轉(zhuǎn)頁面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>跳轉(zhuǎn)頁面</br>hellosmile</div> </body> </html>數(shù)據(jù)庫結(jié)構(gòu)
time為登錄時(shí)間+30分鐘;cishu是錯(cuò)誤次數(shù)
實(shí)現(xiàn)功能:
注冊(cè)頁面:(判斷用戶是否存在),數(shù)據(jù)庫中添加用戶
登錄頁面: 判斷是否連續(xù)錯(cuò)誤5次,連續(xù)錯(cuò)誤5次后需等待30分鐘解凍 賬號(hào),若改換ip后將重新獲取5次機(jī)會(huì)
總結(jié)
以上是生活随笔為你收集整理的PHP+MySQL+JavaScript实现注册登录(防黑客爆破)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C学习笔记-字符串处理函数
- 下一篇: 数据库物理设计