一个基于mysql的登陆验证程序


  1
  2<?   
  3  
  4/******************************************************   
  5  
  6file name: login.php3   
  7  
  8Login Check   
  9  
 10编码: PHP 4   
 11  
 12作者: Kevin Lee < [email protected] >
 13Database: MySQL。   
 14  
 15Host: localhost Database : mydb   
 16  
 17Table structure for table 'user'   
 18  
 19\--------------------------------------------------------   
 20  
 21CREATE TABLE user (   
 22  
 23id smallint(6) NOT NULL auto_increment,   
 24  
 25user varchar(12) NOT NULL,   
 26  
 27passwd varchar(12) NOT NULL,   
 28  
 29name varchar(20),   
 30  
 31email varchar(30),   
 32  
 33level char(1),   
 34  
 35status char(1),   
 36  
 37UNIQUE id (id)   
 38  
 39);   
 40  
 41\--------------------------------------------------------   
 42  
 43*******************************************************/   
 44  
 45?&gt;
 46<script language="javascript">   
 47  
 48function back(){   
 49  
 50history.back();   
 51  
 52}   
 53  
 54function winclose(){   
 55  
 56setTimeout("self.close()",10000);   
 57  
 58}   
 59  
 60</script>
 61<?   
 62  
 63$db_id = mysql_pconnect("localhost", "root", "");   
 64  
 65$sql="select id, user, passwd from user where user='".$name."' and passwd='".$pwd."'";   
 66  
 67$result = mysql_db_query("mydb",$sql);   
 68  
 69$row = mysql_fetch_array($result);   
 70  
 71$id = $row[id] ;   
 72  
 73if ($id!="") {   
 74  
 75session_start();   
 76  
 77session_register("yn");   
 78  
 79$yn="yes" ;   
 80  
 81echo "<html>
 82<body onload='\"javascript:winclose()\"'>";   
 83  
 84echo "你已经成功登陆。。。"."<p>";   
 85  
 86echo "<center>"."窗口10秒钟后自动关闭"."</center>";   
 87  
 88echo "</p></body>
 89";   
 90  
 91}   
 92  
 93else {   
 94  
 95echo "帐号或密码错误!!!";   
 96  
 97echo "
 98<p>";   
 99  
100echo "<center>";   
101  
102echo "<a href='\"#\"' onclick='\"javascript:back()\"'>back</a>";   
103  
104echo "</center>" ;   
105  
106}   
107  
108?&gt;   
109  
110<!--   
111  
112file name: login.htm   
113  
114\-->
115<html>
116<head>
117<title>系统登陆</title>
118<meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
119<style type="text/css">   
120  
121<!--   
122  
123.css1 { font-size: 10pt; color: #FFCC66}   
124  
125\-->   
126  
127</style>
128</head>
129<body bgcolor="#ffffff" leftmargin="0" topmargin="0">
130<form action="login.php3" method="post">
131<table bgcolor="#ffffff" border="1" bordercolor="navajowhite" height="106" style="WIDTH: 210px" width="210">
132<tr bgcolor="#0000ff">
133<td colspan="4">
134<div align="center"><b><font color="#ffffff" face="楷体_GB2312">系统登陆</font></b></div>
135</td>
136</tr>
137<tr bgcolor="#f9fde1" bordercolor="#cccccc">
138<td class="css1" width="71">
139<div align="center">用户帐号</div>
140</td>
141<td align="middle" colspan="3">
142<input name="name" size="14"/>
143</td>
144</tr>
145<tr bgcolor="#f9fde1" bordercolor="#cccccc">
146<td class="css1" width="71">
147<div align="center">用户密码</div>
148</td>
149<td align="middle" colspan="3">
150<input name="pwd" size="14" type="password"/>
151</td>
152</tr>
153<tr bgcolor="#f9fde1" bordercolor="#cccccc">
154<td colspan="4" height="26" style="HEIGHT: 26px">
155<div align="center">
156<input height="20" name="Submit1" style="FONT-SIZE: smaller; HEIGHT: 22px" type="submit" value=" 登 陆 "/>
157</div>
158</td>
159</tr>
160</table>
161</form>
162</body>
163</html>
164<?   
165  
166/************************   
167  
168file name: login_chk.php3   
169  
170************************/   
171  
172if ($yn!="yes") { 
173
174echo "<script language=\"javascript\">\n";   
175  
176echo "<!-- \n";   
177  
178echo "history.back () ;\n";   
179  
180echo "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";   
181  
182echo "--> \n";   
183  
184echo " \n";   
185  
186exit;   
187  
188}   
189  
190?&gt;
191
192Example:   
193  
194<? require("login_chk.php3"); ?>
195<!--file name: sample.php3-->
196<html>
197<head></head>
198<body>   
199  
200Success! You have pass the checking.   
201  
202</body>
203<html></html></html></p>
Published At
Categories with 数据库类
comments powered by Disqus