添加帳號和密碼跟后臺的PHP代碼沒有任何關(guān)系。
10年積累的做網(wǎng)站、網(wǎng)站建設(shè)經(jīng)驗(yàn),可以快速應(yīng)對客戶對網(wǎng)站的新想法和需求。提供各種問題對應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識你,你也不認(rèn)識我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有烏蘇免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。
如果要添加帳號和密碼就必須要登錄Mysql數(shù)據(jù)庫, 在對應(yīng)的管理員的數(shù)據(jù)表中插入username和password.
注意:
一般的password 都是用md5函數(shù)加密的。后臺的數(shù)據(jù)庫的密碼也需要加密后復(fù)制到對應(yīng)的密碼欄,否則依然無法登陸。
提示:
mysql數(shù)據(jù)庫操作最好用phpMyadmin文件來操作,這樣更可視話操作。更適合新手。
index.php
html
head
title登錄界面/title
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
/head
body
?php
//將用戶提交的用戶名和密碼和數(shù)據(jù)庫中的用戶名和密碼逐一比對,如正確,則進(jìn)入2.php,錯誤則提示錯誤。
$username=$_post['username'];
$password=$_post['password'];
$sql="select * from userinfo where username='$username' and password='$password'";
$re=mysql_query($sql);
$row=mysql_num_rows[$re];
if(!$row){
echo "scriptalert('用戶名或密碼錯誤!');history.back(-1);/script";
}
else {
echo '用戶登錄成功!';
echo 'meta http-equiv=refresh content=2;url=2.php';
}
?
form name="login" method="post" action="index.php"
用戶名:input type="text" name="username" /br/
密碼:input type="password" name="password" /br/
input type="submit" name="submit" value="登錄"
/form
/body
html
創(chuàng)建conn.php,連接數(shù)據(jù)庫。
$dns = 'mysql:host=127.0.0.1;dbname=test';
$username = 'root';
$password = 'root';
// 1.連接數(shù)據(jù)庫,創(chuàng)建PDO對象
$pdo = new PDO($dns,$username,$password);
創(chuàng)建login.html,登陸頁面。
用戶名
密 碼
創(chuàng)建login.php,驗(yàn)證賬號密碼。
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST["submit"])){
exit("錯誤執(zhí)行");
}//檢測是否有submit操作
include('conn.php');//鏈接數(shù)據(jù)庫
$name = $_POST['name'];//post獲得用戶名表單值
$pwd = sha1($_POST['password']);//post獲得用戶密碼單值
if ($name $pwd){//如果用戶名和密碼都不為空
$sql = "select * from user where username = '$name' and password='$pwd'";//檢測數(shù)據(jù)庫是否有對應(yīng)的username和password的sql
$stmt = $pdo-prepare($sql);
$stmt-execute();
if($stmt-fetch(PDO::FETCH_BOUND)){//0 false 1 true
header("refresh:0;url=welcome.html");//如果成功跳轉(zhuǎn)至welcome.html頁面
exit;
}else{
echo "用戶名或密碼錯誤";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";//如果錯誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試;
}
}else{//如果用戶名或密碼有空
echo "表單填寫不完整";
echo "
setTimeout(function(){window.location.href='login.html';},1000);
";
//如果錯誤使用js 1秒后跳轉(zhuǎn)到登錄頁面重試;
}
$pdo = null;
創(chuàng)建signup.html,注冊頁面
用戶名:
密 碼:
創(chuàng)建signup.php
header("Content-Type: text/html; charset=utf8");
if(!isset($_POST['submit'])){
exit("錯誤執(zhí)行");
}//判斷是否有submit操作
$name=$_POST['name'];//post獲取表單里的name
$pwd = sha1($_POST['password']);//post獲取表單里的password
include('conn.php');//鏈接數(shù)據(jù)庫
$sql="insert into user(id,username,password) values (null,'$name','$pwd')";//向數(shù)據(jù)庫插入表單傳來的值的sql
$stmt = $pdo-prepare($sql);
$stmt-execute();
$stmt-fetch(PDO::FETCH_BOUND);
if (!$stmt){
die('Error: ' . $stmt-getMessage());//如果sql執(zhí)行失敗輸出錯誤
}else{
echo "注冊成功";//成功輸出注冊成功
}
$pdo = null;//關(guān)閉數(shù)據(jù)庫
分享文章:php登錄系統(tǒng)數(shù)據(jù)庫源碼 php登錄系統(tǒng)數(shù)據(jù)庫源碼在哪
文章源于:http://www.rwnh.cn/article4/hhgiie.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、網(wǎng)站排名、商城網(wǎng)站、微信公眾號、外貿(mào)網(wǎng)站建設(shè)、品牌網(wǎng)站制作
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)