您好,登錄后才能下訂單哦!
利用PHP怎么實(shí)現(xiàn)一個(gè)登錄注冊(cè)功能?針對(duì)這個(gè)問(wèn)題,這篇文章詳細(xì)介紹了相對(duì)應(yīng)的分析和解答,希望可以幫助更多想解決這個(gè)問(wèn)題的小伙伴找到更簡(jiǎn)單易行的方法。
<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>用戶(hù)名:</p> <input type="text" name="username" placeholder="手機(jī)號(hào)/郵箱" /> <p>密碼:</p> <input type="password" name="password" placeholder="密碼可見(jiàn)" /> <br /> <button class="slig-btn">登錄</button> <p> 沒(méi)有賬號(hào)?請(qǐng) <a href="regist.html" rel="external nofollow" >注冊(cè)</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 ></div> </div> </div> </form> <div ></div> </div>
5.注冊(cè)頁(yè)面的form表單代碼
<div class="password-con registered"> <form action="regist.php" method="post"> <div class="psw"> <p class="psw-p1">用戶(hù)名</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="請(qǐng)輸入密碼" /> <span class="cuo">密碼由6-16的字母、數(shù)字、符號(hào)組成</span> </div> <div class="psw"> <p class="psw-p1">確認(rèn)密碼</p> <input type="password" name="repassword" placeholder="請(qǐng)?jiān)俅屋斎朊艽a" /> <span class="cuo">密碼不一致,請(qǐng)重新輸入</span> </div> <div class="psw psw2"> <p class="psw-p1">手機(jī)號(hào)/郵箱</p> <input type="text" name="telphone" placeholder="請(qǐng)輸入手機(jī)/郵箱驗(yàn)證碼" /> <button>獲取短信驗(yàn)證碼</button> </div> <div class="psw psw3"> <p class="psw-p1">驗(yàn)證碼</p> <input type="text" placeholder="請(qǐng)輸入驗(yàn)證碼" /> </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 ></div> </div> <div class="agreement"> <input type="checkbox" name="hobby" /> <p> 我有閱讀并同意 <span>《宅客微購(gòu)網(wǎng)站服務(wù)協(xié)議》</span> </p> </div> <button type="submit" value="注冊(cè)" class="psw-btn">立即注冊(cè)</button> <p class="sign-in"> 已有賬號(hào)?請(qǐng) <a href="login.html" rel="external nofollow" >登錄</a> </p> </form> </div><!-- 注冊(cè)框結(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ù)庫(kù)連接失敗!'; exit(0); }else{ if ($username == ''){ echo '<script>alert("請(qǐng)輸入用戶(hù)名!");history.go(-1);</script>'; exit(0); } if ($password == ''){ echo '<script>alert("請(qǐng)輸入密碼!");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("用戶(hù)名或密碼錯(cuò)誤!");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("請(qǐng)輸入用戶(hù)名!");history.go(-1);</script>'; exit(0); } if ($password == ''){ echo '<script>alert("請(qǐng)輸入密碼");history.go(-1);</script>'; exit(0); } if ($password != $repassword){ echo '<script>alert("密碼與確認(rèn)密碼應(yīng)該一致");history.go(-1);</script>'; exit(0); } if($password == $repassword){ $conn = new mysqli('localhost','root','root','shopping'); if ($conn->connect_error){ echo '數(shù)據(jù)庫(kù)連接失??!'; 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("用戶(hù)名已經(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)繁忙,請(qǐng)稍候!');</script>"; } } } }else{ echo "<script>alert('提交未成功!'); history.go(-1);</script>"; } ?>
關(guān)于利用PHP怎么實(shí)現(xiàn)一個(gè)登錄注冊(cè)功能問(wèn)題的解答就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,如果你還有很多疑惑沒(méi)有解開(kāi),可以關(guān)注億速云行業(yè)資訊頻道了解更多相關(guān)知識(shí)。
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。