程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> MySQL綜合教程 >> 一個基於mysql的登陸驗證程序

一個基於mysql的登陸驗證程序

編輯:MySQL綜合教程

<?
/******************************************************
file name: login.php3
Login Check
編碼: PHP 4
作者: Kevin Lee < [email protected] >
Database: MySQL。
Host: localhost Database : mydb
Table structure for table 'user'
--------------------------------------------------------
CREATE TABLE user (
id smallint(6) NOT NULL auto_increment,
user varchar(12) NOT NULL,
passwd varchar(12) NOT NULL,
name varchar(20),
email varchar(30),
level char(1),
status char(1),
UNIQUE id (id)
);
--------------------------------------------------------
*******************************************************/
?>
<script language="javascript">
function back(){
history.back();
}
function winclose(){
setTimeout("self.close()",10000);
}
</script>
<?
$db_id = mysql_pconnect("localhost", "root", "");
$sql="select id, user, passwd from user where user='".$name."' and passwd='".$pwd."'";
$result = mysql_db_query("mydb",$sql);
$row = mysql_fetch_array($result);
$id = $row[id] ;
if ($id!="") {
session_start();
session_register("yn");
$yn="yes"  ;
echo "<html><body onload=\"javascript:winclose()\">";
echo "你已經成功登陸。。。"."<p>";
echo "<center>"."窗口10秒鐘後自動關閉"."</center>";
echo "</body></html>";
}
else {
echo "帳號或密碼錯誤!!!";
echo "<P>";
echo "<center>";
echo "<a href=\"#\" onclick=\"javascript:back()\">back</a>";
echo "</center>" ;
}
?>
<!--
file name: login.htm
-->
<html>
<head>
<title>系統登陸</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
.css1 {  font-size: 10pt; color: #FFCC66}
-->
</style>
</head>
<body bgcolor="#ffffff" topmargin=0 leftmargin=0>
<form method="post" action="login.php3">
<table width="210" bgcolor="#ffffff" height="106" bordercolor="navajowhite" border="1" >
<tr bgcolor="#0000ff">
<td colspan="4">
<div align="center"><b><font color="#ffffff" face="楷體_GB2312">系統登陸</font></b></div>
</td>
</tr>
<tr bgcolor="#f9fde1" bordercolor="#cccccc">
<td width="71" class="css1">
<div align="center">用戶帳號</div>
</td>
<td colspan="3" align=middle>
<input name="name" size="14" >
</td>
</tr>
<tr bgcolor="#f9fde1" bordercolor="#cccccc">
<td width="71" class="css1">
<div align="center">用戶密碼</div>
</td>
<td colspan="3" align=middle>
<input type="password" name="pwd" size="14" >
</td>
</tr>
<tr bgcolor="#f9fde1" bordercolor="#cccccc">
<td colspan="4" height="26" >
<div align="center">
<input type="submit" name="Submit1" value="  登 陸 " height="20" >
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
<?
/************************
file name: login_chk.php3
************************/
if ($yn!="yes") {

echo "<script language=\"javascript\">\n";
echo "<!-- \n";
echo "history.back () ;\n";
echo "window.open ('../login/login.htm','login','height=116,width=210,top=120,left=200,toolbar=no,menubar=no,scrobllbar=no,resizable=no,location=no,status=no')\n";
echo "--> \n";
echo "</script> \n";
exit;
}
?>

Example:
<? require("login_chk.php3"); ?>
<!--file name: sample.php3-->
<html>
<head></head>
<body>
Success! You have pass the checking.
</body>
<html>


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved