PHP實(shí)現(xiàn)的登錄頁(yè)面信息提示功能示例
本文實(shí)例講述了PHP實(shí)現(xiàn)的登錄頁(yè)面信息提示功能。分享給大家供大家參考,具體如下:
login.php:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Insert title here</title> </head> <body> <form action="check_login.php" name="loginform" method="post"> 帳號(hào): <input type="text" name="name" /> 密碼: <input type="password" name="pwd" /> <input type="submit" value="登 錄" /> </form> <?php echo "<br/>"; //通過 error 值,確定提示信息 if(!empty($_GET['error'])){ $error=$_GET['error']; If($error==1){ Echo "<font color ='red'>您輸入的賬號(hào)或密碼錯(cuò)誤!</font>"; }elseif ($error==2){ Echo "<font color ='red'>您輸入的賬號(hào)或密碼正確!</font>"; } } ?> </body> </html>
check_login.php:
<?php header("Content-type: text/html; charset=utf-8"); session_start(); //初始化session變量 $username = $_POST['name']; //接收表單提交的用戶名 $password=md5($_POST['pwd']); //接收表單提交的密碼 class chkinput //定義類 { var $name; var $pwd; function chkinput($x,$y) //定義一個(gè)方法 { $this->name=$x; //將管理員名稱傳給類對(duì)象$this->name $this->pwd=$y; //將管理員密碼傳給類對(duì)象$this->pwd } function checkinput() { include("conn.php"); //連接數(shù)據(jù)庫(kù)文件 $sql=mysql_query("select username,password from admin where username='".$this->name."' and password='".$this->pwd."'",$conn); $info=mysql_fetch_array($sql); //檢索管理員名稱和密碼是否正確 if($info==false) //如果管理員名稱或密碼不正確,則彈出相關(guān)提示信息 { header("location:login.php?error=1"); exit; } else //如果管理員名稱或密碼正確,則直接跳轉(zhuǎn)到登陸成功后界面 { header("location:login.php?error=2"); $_SESSION['admin_name']=$info['username']; //將管理員名稱存到$_SESSION[admin_name]變量中 $_SESSION['pwd']=$info['password']; ////將管理員名稱存到$_SESSION[pwd]變量中 } } } $obj=new chkinput(trim($username),trim($password)); //創(chuàng)建對(duì)象 $obj->checkinput(); //調(diào)用類 ?>
conn.php:
<?php header("Content-type: text/html; charset=utf-8"); $conn = mysql_connect("localhost","root","111111"); if(!$conn) { die("連接數(shù)據(jù)庫(kù)失敗".mysql_error()); } mysql_select_db("design") or die("數(shù)據(jù)庫(kù)選擇失敗".mysql_error()); mysql_query("set names 'uft8'"); ?>
更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP網(wǎng)絡(luò)編程技巧總結(jié)》、《PHP基本語(yǔ)法入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫(kù)操作入門教程》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總》
希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
Mac系統(tǒng)下使用brew搭建PHP(LNMP/LAMP)開發(fā)環(huán)境
這篇文章主要介紹了Mac系統(tǒng)下使用brew搭建PHP(LNMP/LAMP)開發(fā)環(huán)境,本文講解了使用Brew手動(dòng)搭建PHP的開發(fā)環(huán)境,包括Apache、Nginx、PHP、MySQL、MongoDB、PHPMyAdmin等配置,需要的朋友可以參考下2015-03-03php中echo、print和print_r的區(qū)別點(diǎn)及用法總結(jié)
在本篇文章里小編給大家整理的是一篇關(guān)于php中echo、print和print_r的區(qū)別點(diǎn)及用法總結(jié)內(nèi)容,有需要的朋友們可以學(xué)習(xí)下。2021-12-12在php中判斷一個(gè)請(qǐng)求是ajax請(qǐng)求還是普通請(qǐng)求的方法
如何在php中判斷一個(gè)網(wǎng)頁(yè)請(qǐng)求是ajax請(qǐng)求還是普通請(qǐng)求?你可以通過傳遞參數(shù)的方法來實(shí)現(xiàn),例如使用如下網(wǎng)址請(qǐng)求2011-06-06深入PHP中的HashTable結(jié)構(gòu)詳解
本篇文章是對(duì)PHP中的HashTable結(jié)構(gòu)進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06PHP 正則表達(dá)式之正則處理函數(shù)小結(jié)(preg_match,preg_match_all,preg_replace,pr
本節(jié)我們就來介紹一下PHP中基于perl的正則表達(dá)式處理函數(shù),主要包含了分割, 匹配,查找,替換等等處理操作,依舊是配合示例講解,讓我們開始吧2012-10-10php strtotime 函數(shù)UNIX時(shí)間戳
int strtotime ( string time [, int now]) 本函數(shù)預(yù)期接受一個(gè)包含英文日期格式的字符串并嘗試將其解析為 UNIX 時(shí)間戳。2009-01-01php實(shí)現(xiàn)與erlang的二進(jìn)制通訊實(shí)例解析
這篇文章主要介紹了php實(shí)現(xiàn)與erlang的二進(jìn)制通訊實(shí)例解析,需要的朋友可以參考下2014-07-07