php注冊(cè)登錄系統(tǒng)簡(jiǎn)化版
登錄注冊(cè)系統(tǒng)是日常上網(wǎng)最普通的操作,我設(shè)了一個(gè)分類一步步完善注冊(cè)登錄系統(tǒng),若哪里有誤,請(qǐng)見諒。
所用語言:php
數(shù)據(jù)庫 :mysql
本次實(shí)現(xiàn)功能:
1.用戶注冊(cè)
2.用戶登錄
主要文件:
完整代碼
1 sql 在已有的數(shù)據(jù)庫里創(chuàng)建user表,id,username,password三個(gè)字段
2 connect.php 數(shù)據(jù)庫配置文件
<?php $server="localhost";//主機(jī) $db_username="";//你的數(shù)據(jù)庫用戶名 $db_password="";//你的數(shù)據(jù)庫密碼 $con = mysql_connect($server,$db_username,$db_password);//鏈接數(shù)據(jù)庫 if(!$con){ die("can't connect".mysql_error());//如果鏈接失敗輸出錯(cuò)誤 } mysql_select_db('test',$con);//選擇數(shù)據(jù)庫(我的是test) ?>
3 signup.html 注冊(cè)表單
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用戶注冊(cè)頁面</title> </head> <body> <form action="signup.php" method="post"> <p>用戶名:<input type="text" name="name"></p> <p>密 碼: <input type="text" name="password"></p> <p><input type="submit" name="submit" value="注冊(cè)"></p> </form> </body> </html>
4 signup.php 注冊(cè)程序
<?php header("Content-Type: text/html; charset=utf8"); if(!isset($_POST['submit'])){ exit("錯(cuò)誤執(zhí)行"); }//判斷是否有submit操作 $name=$_POST['name'];//post獲取表單里的name $password=$_POST['password'];//post獲取表單里的password include('connect.php');//鏈接數(shù)據(jù)庫 $q="insert into user(id,username,password) values (null,'$name','$password')";//向數(shù)據(jù)庫插入表單傳來的值的sql $reslut=mysql_query($q,$con);//執(zhí)行sql if (!$reslut){ die('Error: ' . mysql_error());//如果sql執(zhí)行失敗輸出錯(cuò)誤 }else{ echo "注冊(cè)成功";//成功輸出注冊(cè)成功 } mysql_close($con);//關(guān)閉數(shù)據(jù)庫 ?>
注冊(cè)流程完成,下面是用戶登錄
5 login.html 登錄表單
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登陸</title> </head> <body> <form name="login" action="login.php" method="post"> <p>用戶名<input type=text name="name"></p> <p>密 碼<input type=password name="password"></p> <p><input type="submit" name="submit" value="登錄"></p> </form> </body> </html>
6 login.php 登錄程序
<?PHP header("Content-Type: text/html; charset=utf8"); if(!isset($_POST["submit"])){ exit("錯(cuò)誤執(zhí)行"); }//檢測(cè)是否有submit操作 include('connect.php');//鏈接數(shù)據(jù)庫 $name = $_POST['name'];//post獲得用戶名表單值 $passowrd = $_POST['password'];//post獲得用戶密碼單值 if ($name && $passowrd){//如果用戶名和密碼都不為空 $sql = "select * from user where username = '$name' and password='$passowrd'";//檢測(cè)數(shù)據(jù)庫是否有對(duì)應(yīng)的username和password的sql $result = mysql_query($sql);//執(zhí)行sql $rows=mysql_num_rows($result);//返回一個(gè)數(shù)值 if($rows){//0 false 1 true header("refresh:0;url=welcome.html");//如果成功跳轉(zhuǎn)至welcome.html頁面 exit; }else{ echo "用戶名或密碼錯(cuò)誤"; echo " <script> setTimeout(function(){window.location.href='login.html';},1000); </script> ";//如果錯(cuò)誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試; } }else{//如果用戶名或密碼有空 echo "表單填寫不完整"; echo " <script> setTimeout(function(){window.location.href='login.html';},1000); </script>"; //如果錯(cuò)誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試; } mysql_close();//關(guān)閉數(shù)據(jù)庫 ?>
7 welcome.html 登錄成功跳轉(zhuǎn)頁面
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登陸成功</title> </head> <body> 歡迎光臨 </body> </html>
至此一個(gè)簡(jiǎn)單的完整的注冊(cè)登錄系統(tǒng)完成,代碼很簡(jiǎn)單沒有考慮驗(yàn)證安全性健壯性,之后在進(jìn)行完善。
希望本文所述對(duì)大家學(xué)習(xí)php程序設(shè)計(jì)有所幫助。
相關(guān)文章
php下foreach提示W(wǎng)arning:Invalid argument supplied for foreach()
這篇文章主要介紹了php下foreach提示W(wǎng)arning:Invalid argument supplied for foreach()的解決方法,是很多開發(fā)者在進(jìn)行PHP程序設(shè)計(jì)的過程中經(jīng)常會(huì)遇到的問題,需要的朋友可以參考下2014-11-11PHP PDO數(shù)據(jù)庫操作預(yù)處理與注意事項(xiàng)
今天小編就為大家分享一篇關(guān)于PHP PDO數(shù)據(jù)庫操作預(yù)處理與注意事項(xiàng),小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧2019-03-03簡(jiǎn)單實(shí)用的PHP防注入類實(shí)例
這篇文章主要介紹了簡(jiǎn)單實(shí)用的PHP防注入類實(shí)例,以兩個(gè)簡(jiǎn)單的防注入類為例介紹了PHP防注入的原理與技巧,對(duì)網(wǎng)站安全建設(shè)來說非常具有實(shí)用價(jià)值,需要的朋友可以參考下2014-12-12PHP實(shí)現(xiàn)仿Google分頁效果的分頁函數(shù)
這篇文章主要介紹了PHP實(shí)現(xiàn)仿Google分頁效果的分頁函數(shù),實(shí)例分析了php實(shí)現(xiàn)分頁的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下2015-07-07Joomla下利用configuration.php存儲(chǔ)簡(jiǎn)單數(shù)據(jù)
Joomla下利用configuration.php存儲(chǔ)簡(jiǎn)單數(shù)據(jù)的代碼,需要的朋友可以參考下。2010-05-05php中在PDO中使用事務(wù)(Transaction)
事務(wù) (Transaction) 是操作數(shù)據(jù)庫中很重要的一個(gè)功能, 它可以讓你預(yù)定一條, 或者一系列 SQL 語句, 然后一起執(zhí)行2011-05-05php 網(wǎng)頁播放器用來播放在線視頻的代碼(自動(dòng)判斷并選擇視頻文件類型)
其實(shí)這里的php 視頻播放代碼基本上常見的視頻格式都支持,用正則匹配文件擴(kuò)展名,并根據(jù)文件擴(kuò)展名的不同調(diào)用相應(yīng)的在線播放器代碼。2010-06-06PHP調(diào)試函數(shù)和日志記錄函數(shù)分享
這篇文章主要介紹了PHP調(diào)試函數(shù)和日志記錄函數(shù)分享,本文分享的函數(shù)都是自己項(xiàng)目中使用的,需要的朋友可以參考下2015-01-01