這個(gè)本質(zhì)上說(shuō)是可選的,文件可以替代數(shù)據(jù)庫(kù)的作用,但是,文件數(shù)量一旦多了之后,索引文件以及查找其中內(nèi)容會(huì)變得非常的慢,而且數(shù)據(jù)庫(kù)起到的作用是,有序的索引大量的數(shù)據(jù),并使調(diào)用修改變得簡(jiǎn)便。
創(chuàng)新互聯(lián)建站是專業(yè)的額濟(jì)納網(wǎng)站建設(shè)公司,額濟(jì)納接單;提供成都做網(wǎng)站、成都網(wǎng)站制作,網(wǎng)頁(yè)設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行額濟(jì)納網(wǎng)站開(kāi)發(fā)網(wǎng)頁(yè)制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛(ài)的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來(lái)合作!
所以雖然數(shù)據(jù)庫(kù)可以不用,但還是建議將數(shù)據(jù)庫(kù)與PHP程序綁定,這樣方便你自己,也是一種發(fā)展趨勢(shì)。
將下面代碼保存為login.php 和 confirm.php,然后運(yùn)行l(wèi)ogin.php就可以
login.php
!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" ""
html
head
title New Document /title
meta http-equiv="content-type" content="text/html; charset=utf-8"
meta name="Generator" content="EditPlus"
meta name="Author" content=""
meta name="Keywords" content=""
meta name="Description" content=""
/head
body
form name="form1" method="post" action="confirm.php"
p用戶名:input type="text" name="user"/p
p密碼:input type="password" name="pwd"/p
pinput type="submit" name="b1"/p
/form
/body
/html
confirm.php
?
echo 'meta http-equiv="content-type" content="text/html; charset=utf-8"';
$user = isset($_POST['user'])? $_POST['user'] : '';
$pwd = isset($_POST['pwd'])? $_POST['pwd'] : '';
if(empty($user) || empty($pwd)){
echo '用戶名和密碼不能為空';
exit();
}
if($user=='user' $pwd=='pwd'){
echo '登陸成功';
}else{
echo '用戶名或密碼錯(cuò)誤';
}
?
信息終究是要存儲(chǔ)的,最終都需要存儲(chǔ)在文件中,數(shù)據(jù)庫(kù)在這個(gè)事情上可以讓為是幫你管理一大堆的“文件”,其他的如csv、excel,也算是變相的一種數(shù)據(jù)庫(kù)了;
如果非不要數(shù)據(jù)庫(kù),建議直接生成靜態(tài)html吧,可以用markdown之類的工具。修改不方便。
有啊。直接將賬號(hào)密碼POST 到另一個(gè)PHP 接受。。
index.php
form name="form1" method="post" action="confirm.php"
p用戶名:input type="text" name="user"/p
p密碼:input type="password" name="pwd"/p
pinput type="submit" /p
/form
confirm.php
?php
$user = isset($_POST['user'])? $_POST['user'] : '';
$pwd = isset($_POST['pwd'])? $_POST['pwd'] : '';
if(empty($user) || empty($pwd)){
echo '用戶名和密碼不能為空';
exit();
}
if($user=='user' $pwd=='pwd'){
echo '登陸成功';
}else{
echo '用戶名或密碼錯(cuò)誤';
}
?
不用數(shù)據(jù)庫(kù)就把數(shù)據(jù)存于文件,比如:php文件、XML文件、txt文件等等
這里假設(shè)你的主頁(yè)是index.php,登錄前頁(yè)面是login.php,用戶名user1的密碼為123。當(dāng)然,給你提供的是PHP方法,所以你必須配置好了PHP并且每頁(yè)都必須是PHP。
每個(gè)需要登錄后查看的頁(yè)面的開(kāi)始寫(一定要最開(kāi)始,前面不能有任何字符包括回車或者空格)
?php session_start();if(!isset($_SESSION['pass']))header("Location: login.php");?
在登錄頁(yè)面最開(kāi)始寫:
?php session_start();$usr=array('user1'='123','user2'='456');if(isset[$_POST['usr']]isset[$_POST['pwd']]isset[$usr[$_POST['usr']]]$_POST['pwd']==$usr[$_POST['usr']])$_SESSION['pass']=1;if(isset($_SESSION['pass']))header("Location: index.php");?
登錄頁(yè)內(nèi)容里必須有form元素具有method屬性值為post。
form元素里必須具有兩個(gè)input具有name屬性值分別為usr和pwd,最后一個(gè)按鈕建議用input type=submit。例如:
form method="post"
Name: input name="usr"/br/
Password: input name="pwd"/br/
input type="submit" value="login"/
/form
直接寫的沒(méi)測(cè)試,希望能正確吧。
名稱欄目:php不用數(shù)據(jù)庫(kù),php只能用mysql數(shù)據(jù)庫(kù)
分享網(wǎng)址:http://chinadenli.net/article12/heecgc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供、定制網(wǎng)站、網(wǎng)站導(dǎo)航、微信公眾號(hào)、云服務(wù)器、外貿(mào)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)