基于PHP的登錄和注冊的功能的實現(xiàn)
1.新建三個html文件,兩個php文件和若干個CSS文件和若干個JS文件
2.登錄的html頁面顯示效果圖
3.注冊的頁面的顯示效果圖
4.登錄頁面的form表單代碼
<div class="sign-con w1200"> <img src="img/logn-tu.gif" class="sign-contu f-l"/> <form action="login.php" method="post"> <div class="sign-ipt f-l"> <p>用戶名:</p> <input type="text" name="username" placeholder="手機號/郵箱" /> <p>密碼:</p> <input type="password" name="password" placeholder="密碼可見" /> <br /> <button class="slig-btn">登錄</button> <p> 沒有賬號?請 <a href="regist.html" rel="external nofollow" >注冊</a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="wj">忘記密碼?</a> </p> <div class="sign-qx"> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="f-r"> <img src="img/sign-xinlan.gif" /> </a> <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" class="qq f-r"> <img src="img/sign-qq.gif" /> </a> <div style="clear: both;"></div> </div> </div> </form> <div style="clear: both;"></div> </div>
5.注冊頁面的form表單代碼
<div class="password-con registered"> <form action="regist.php" method="post"> <div class="psw"> <p class="psw-p1">用戶名</p> <input type="text" name="username" placeholder="HR了" /> <span class="dui"></span> </div> <div class="psw"> <p class="psw-p1">輸入密碼</p> <input type="password" name="password" placeholder="請輸入密碼" /> <span class="cuo">密碼由6-16的字母、數(shù)字、符號組成</span> </div> <div class="psw"> <p class="psw-p1">確認密碼</p> <input type="password" name="repassword" placeholder="請再次輸入密碼" /> <span class="cuo">密碼不一致,請重新輸入</span> </div> <div class="psw psw2"> <p class="psw-p1">手機號/郵箱</p> <input type="text" name="telphone" placeholder="請輸入手機/郵箱驗證碼" /> <button>獲取短信驗證碼</button> </div> <div class="psw psw3"> <p class="psw-p1">驗證碼</p> <input type="text" placeholder="請輸入驗證碼" /> </div> <div class="yanzhentu"> <div class="yz-tu f-l"> <img src="img/psw-yanzhengtu.gif" /> </div> <p class="f-l"> 看不清楚? <a href="#" rel="external nofollow" rel="external nofollow" rel="external nofollow" rel="external nofollow" >換張圖</a> </p> <div style="clear: both;"></div> </div> <div class="agreement"> <input type="checkbox" name="hobby" /> <p> 我有閱讀并同意 <span>《宅客微購網(wǎng)站服務協(xié)議》</span> </p> </div> <button type="submit" value="注冊" class="psw-btn">立即注冊</button> <p class="sign-in"> 已有賬號?請 <a href="login.html" rel="external nofollow" >登錄</a> </p> </form> </div><!-- 注冊框結(jié)束 -->
6.login.php代碼
<?php header("Content-type: text/html; charset=utf-8"); $username = $_POST['username']; $password = $_POST['password']; $conn = new mysqli('localhost','root','root','shopping'); if ($conn->connect_error){ echo '數(shù)據(jù)庫連接失??!'; exit(0); }else{ if ($username == ''){ echo '<script>alert("請輸入用戶名!");history.go(-1);</script>'; exit(0); } if ($password == ''){ echo '<script>alert("請輸入密碼!");history.go(-1);</script>'; exit(0); } $sql = "select username,password from userinfo where username = '$_POST[username]' and password = '$_POST[password]'"; $result = $conn->query($sql); $number = mysqli_num_rows($result); if ($number) { echo '<script>window.location="index.html";</script>'; } else { echo '<script>alert("用戶名或密碼錯誤!");history.go(-1);</script>'; } } ?>
7.regist.php代碼
<?php header("Content-type: text/html; charset=utf-8"); $username = $_POST['username']; $password = $_POST['password']; $repassword = $_POST['repassword']; $telphone = $_POST['telphone']; if ($username == ''){ echo '<script>alert("請輸入用戶名!");history.go(-1);</script>'; exit(0); } if ($password == ''){ echo '<script>alert("請輸入密碼");history.go(-1);</script>'; exit(0); } if ($password != $repassword){ echo '<script>alert("密碼與確認密碼應該一致");history.go(-1);</script>'; exit(0); } if($password == $repassword){ $conn = new mysqli('localhost','root','root','shopping'); if ($conn->connect_error){ echo '數(shù)據(jù)庫連接失??!'; exit(0); }else { $sql = "select username from userinfo where username = '$_POST[username]'"; $result = $conn->query($sql); $number = mysqli_num_rows($result); if ($number) { echo '<script>alert("用戶名已經(jīng)存在");history.go(-1);</script>'; } else { $sql_insert = "insert into userinfo (username,password,telphone) values('$_POST[username]','$_POST[password]','$_POST[telphone]')"; $res_insert = $conn->query($sql_insert); if ($res_insert) { echo '<script>window.location="index.html";</script>'; } else { echo "<script>alert('系統(tǒng)繁忙,請稍候!');</script>"; } } } }else{ echo "<script>alert('提交未成功!'); history.go(-1);</script>"; } ?>
8.進入首頁后的圖片
9.數(shù)據(jù)庫的圖片
到此這篇關(guān)于基于PHP的登錄和注冊的功能的實現(xiàn)的文章就介紹到這了,更多相關(guān)PHP實現(xiàn)登錄和注冊的功能內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
LotusPhp筆記之:基于ObjectUtil組件的使用分析
學習要先易后難,好吧,我剛開始學習LotusPhp的時候,就是從最容易的Logger和ObjectUtil開始的,這2個組件基本沒有什么難度。一看就會2013-05-05php+webSoket實現(xiàn)聊天室示例代碼(附源碼)
本篇文章主要介紹了php+webSoket搭建chatServer示例(附源碼)的資料,這里整理了詳細的代碼,有需要的小伙伴可以參考下。2017-02-02PHP對稱加密函數(shù)實現(xiàn)數(shù)據(jù)的加密解密
本文詳細介紹了PHP一個簡單的對稱加密函數(shù)實現(xiàn)數(shù)據(jù)的加密解密,詳細的介紹了對稱加密和非對稱加密,有需要的可以了解一下。2016-10-10PHP通過bypass disable functions執(zhí)行系統(tǒng)命令的方法匯總
這篇文章主要介紹了PHP通過bypass disable functions執(zhí)行系統(tǒng)命令的方法匯總,需要的朋友可以參考下2018-05-05thinkphp3.2框架中where條件查詢用法總結(jié)
這篇文章主要介紹了thinkphp3.2框架中where條件查詢用法,總結(jié)分析了thinkphp3.2中where條件查詢中常用的各種查詢條件、以及各種復合查詢實現(xiàn)方法,需要的朋友可以參考下2019-08-08在Yii2中使用Pjax導致Yii2內(nèi)聯(lián)腳本載入失敗的原因分析
這篇文章主要介紹了在Yii2中使用Pjax導致Yii2內(nèi)聯(lián)腳本載入失敗的原因分析的相關(guān)資料,需要的朋友可以參考下2016-03-03