php注冊登錄系統(tǒng)簡化版
登錄注冊系統(tǒng)是日常上網(wǎng)最普通的操作,我設了一個分類一步步完善注冊登錄系統(tǒng),若哪里有誤,請見諒。
所用語言:php
數(shù)據(jù)庫 :mysql
本次實現(xiàn)功能:
1.用戶注冊
2.用戶登錄
主要文件:

完整代碼
1 sql 在已有的數(shù)據(jù)庫里創(chuàng)建user表,id,username,password三個字段
2 connect.php 數(shù)據(jù)庫配置文件
<?php
$server="localhost";//主機
$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());//如果鏈接失敗輸出錯誤
}
mysql_select_db('test',$con);//選擇數(shù)據(jù)庫(我的是test)
?>
3 signup.html 注冊表單
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>用戶注冊頁面</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="注冊"></p> </form> </body> </html>
4 signup.php 注冊程序
<?php
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST['submit'])){
exit("錯誤執(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í)行失敗輸出錯誤
}else{
echo "注冊成功";//成功輸出注冊成功
}
mysql_close($con);//關閉數(shù)據(jù)庫
?>
注冊流程完成,下面是用戶登錄
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("錯誤執(zhí)行");
}//檢測是否有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'";//檢測數(shù)據(jù)庫是否有對應的username和password的sql
$result = mysql_query($sql);//執(zhí)行sql
$rows=mysql_num_rows($result);//返回一個數(shù)值
if($rows){//0 false 1 true
header("refresh:0;url=welcome.html");//如果成功跳轉至welcome.html頁面
exit;
}else{
echo "用戶名或密碼錯誤";
echo "
<script>
setTimeout(function(){window.location.href='login.html';},1000);
</script>
";//如果錯誤使用js 1秒后跳轉到登錄頁面重試;
}
}else{//如果用戶名或密碼有空
echo "表單填寫不完整";
echo "
<script>
setTimeout(function(){window.location.href='login.html';},1000);
</script>";
//如果錯誤使用js 1秒后跳轉到登錄頁面重試;
}
mysql_close();//關閉數(shù)據(jù)庫
?>
7 welcome.html 登錄成功跳轉頁面
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>登陸成功</title> </head> <body> 歡迎光臨 </body> </html>
至此一個簡單的完整的注冊登錄系統(tǒng)完成,代碼很簡單沒有考慮驗證安全性健壯性,之后在進行完善。
希望本文所述對大家學習php程序設計有所幫助。
相關文章
php下foreach提示W(wǎng)arning:Invalid argument supplied for foreach()
這篇文章主要介紹了php下foreach提示W(wǎng)arning:Invalid argument supplied for foreach()的解決方法,是很多開發(fā)者在進行PHP程序設計的過程中經(jīng)常會遇到的問題,需要的朋友可以參考下2014-11-11
PHP實現(xiàn)仿Google分頁效果的分頁函數(shù)
這篇文章主要介紹了PHP實現(xiàn)仿Google分頁效果的分頁函數(shù),實例分析了php實現(xiàn)分頁的相關技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-07-07
Joomla下利用configuration.php存儲簡單數(shù)據(jù)
Joomla下利用configuration.php存儲簡單數(shù)據(jù)的代碼,需要的朋友可以參考下。2010-05-05
php 網(wǎng)頁播放器用來播放在線視頻的代碼(自動判斷并選擇視頻文件類型)
其實這里的php 視頻播放代碼基本上常見的視頻格式都支持,用正則匹配文件擴展名,并根據(jù)文件擴展名的不同調用相應的在線播放器代碼。2010-06-06

