php不連接數(shù)據(jù)庫登陸 php無法連接數(shù)據(jù)庫

制作一個php的登陸頁面 無需連接數(shù)據(jù)庫 只需要昵稱就能進入的聊天室

這里假設(shè)你的主頁是index.php,登錄前頁面是login.php,用戶名user1的密碼為123。當(dāng)然,給你提供的是PHP方法,所以你必須配置好了PHP并且每頁都必須是PHP。

我們提供的服務(wù)有:成都網(wǎng)站設(shè)計、網(wǎng)站建設(shè)、微信公眾號開發(fā)、網(wǎng)站優(yōu)化、網(wǎng)站認(rèn)證、徐匯ssl等。為成百上千家企事業(yè)單位解決了網(wǎng)站和推廣的問題。提供周到的售前咨詢和貼心的售后服務(wù),是有科學(xué)管理、有技術(shù)的徐匯網(wǎng)站制作公司

每個需要登錄后查看的頁面的開始寫(一定要最開始,前面不能有任何字符包括回車或者空格)

?php session_start();if(!isset($_SESSION['pass']))header("Location: login.php");?

在登錄頁面最開始寫:

?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");?

登錄頁內(nèi)容里必須有form元素具有method屬性值為post。

form元素里必須具有兩個input具有name屬性值分別為usr和pwd,最后一個按鈕建議用input type=submit。例如:

form method="post"

Name: input name="usr"/br/

Password: input name="pwd"/br/

input type="submit" value="login"/

/form

直接寫的沒測試,希望能正確吧。

在thinkphp怎樣不連接數(shù)據(jù)庫連接

config.php

?php

return array(

'APP_DEBUG' = true, // 開啟調(diào)試模式

'DB_TYPE'= 'mysql', // 數(shù)據(jù)庫類型

'DB_HOST'= 'localhost', // 數(shù)據(jù)庫朋務(wù)器地址

'DB_NAME'='test', // 數(shù)據(jù)庫名稱

'DB_USER'='root', // 數(shù)據(jù)庫用戶名

'DB_PWD'='', // 數(shù)據(jù)庫密碼

'DB_PORT'='3306', // 數(shù)據(jù)庫端口

'DB_PREFIX'='think_', // 數(shù)據(jù)表前綴

);

?

UserAction.class.php

class UserAction extends Action {

public function registerdo(){

$User = M("user");

if($User-create()) {//如果在這里沒報錯,估計沒什麼問題啊

if( $User- add()) { //這里是把數(shù)據(jù)寫入數(shù)據(jù)庫,要不這樣,你先把 cretate()屏蔽掉,看看能不能寫入

$this - success();

}

else

{ $this - error();

}

else

{ $this - error();

}

}

}

registerdo.html

html

form action="__URL__/registerdo" method="post"

useridinput type="text"/ name="userid"

passwordinput type="text"/ name="password"

input type="submit"/

/form

/html

網(wǎng)站無法連接數(shù)據(jù)庫怎么處理?

您好,關(guān)于數(shù)據(jù)庫無法連接的,大致總結(jié)了一下常見程序的數(shù)據(jù)庫鏈接文件到底是哪一個:1. 帝國系統(tǒng)網(wǎng)站數(shù)據(jù)庫配置文件路徑:web/e/class/config.php2. shopex系統(tǒng)網(wǎng)站數(shù)據(jù)庫配置文件路徑:web/config/config.php3. DEDECMS(織夢)系統(tǒng)網(wǎng)站數(shù)據(jù)庫配置文件路徑:web/data/ common.inc.php4. php168系統(tǒng)網(wǎng)站的數(shù)據(jù)庫配置文件路徑:web/php168/mysql_config.php5. 其他.net的網(wǎng)站一般web/web.config文件是數(shù)據(jù)庫配置文件6.phpcms系統(tǒng)的數(shù)據(jù)庫配置文件路徑:web/include/config.inc.php7.discuz論壇系統(tǒng)的網(wǎng)站的數(shù)據(jù)庫配置文件一般3個,分別為: web/uc_server/data/config.inc.phpweb/config/config_global.phpweb/config/config_ucenter.php可以根據(jù)您具體的數(shù)據(jù)庫信息修改一下數(shù)據(jù)庫鏈接文件,當(dāng)您數(shù)據(jù)庫無法連接上的時候,(前提是先確定好我們數(shù)據(jù)庫是正常的,也就是登陸您數(shù)據(jù)庫高級管理看可以不可以進去,如果可以一般是數(shù)據(jù)庫就沒什么問題的了)。

php不用數(shù)據(jù)庫設(shè)計登錄界面

有啊。直接將賬號密碼POST 到另一個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 '用戶名或密碼錯誤';

}

?

我想用PHP寫一個PHP登陸界面,不需要連接數(shù)據(jù)庫的.

將下面代碼保存為login.php 和 confirm.php,然后運行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 '用戶名或密碼錯誤';

}

?

PHP登陸注冊頁在本地測試時,出現(xiàn)連接數(shù)據(jù)庫失敗的情況怎么辦?

1、檢查環(huán)境正常

使用mysql -u root -p 可以進入MySQL操作界面

直接使用/usr/local/php5/bin/php /web/test.php執(zhí)行可以連上數(shù)據(jù)庫

2、打開hosts加入

復(fù)制代碼代碼如下:127.0.0.1 qttc

使用qttc當(dāng)主機連接也正常,唯獨就不認(rèn)localhost。

3、localhost連接方式不同導(dǎo)致

為了了解PHP連接數(shù)據(jù)庫時,主機填寫localhost與其它的區(qū)別閱讀了大量資料,最后得知:

當(dāng)主機填寫為localhost時mysql會采用 unix domain socket連接

當(dāng)主機填寫為127.0.0.1時mysql會采用tcp方式連接

這是linux套接字網(wǎng)絡(luò)的特性,win平臺不會有這個問題

4、解決方法

在my.cnf的[mysql]區(qū)段里添加

復(fù)制代碼代碼如下:

protocol=tcp

保存重啟MySQL,問題解決!

當(dāng)前題目:php不連接數(shù)據(jù)庫登陸 php無法連接數(shù)據(jù)庫
文章地址:http://muchs.cn/article34/hphose.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供做網(wǎng)站、ChatGPT、App設(shè)計、網(wǎng)站制作、品牌網(wǎng)站制作網(wǎng)站維護

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站建設(shè)