使用者註冊是很多網站都必須用的功能,實現註冊方法很多,今天我就把我方法拿出來共用一下吧,我把註冊填表檔案,與判斷儲存資料檔案分開,reg.htm 與reg.asp,這樣做的好處很多,我想這個不用我多說了吧,看了我以前的文章都應該知道了,我的文章在www.111cn.net裡面有很多,下面看代碼.reg.htm,效果圖我就不貼了,
<table width="100%"border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="250" height="77" ><div align="center"></div></td>
<td > </td>
<td width="300"><div align="right"><a href="x_wai_chuli.asp?xlei=newman"></a></div></td>
</tr>
</table>
<div style="position: relative; top:80px; width:400px; height:300px; left:30%">
<table width="600" border="0" cellpadding="0" cellspacing="0">
<form id="form1" name="form1" method="post" action="singin.asp">
<tr>
<td height="50"> </td>
<td height="50"><div align="center"><font color="#B4CFED" size="3"><b>使用者註冊</b></font></div></td>
<td height="50"> </td>
</tr>
<tr>
<td width="118" height="40"><div align="right"><b><font color="#FFFFFF">學號:</font></b></div></td>
<td width="210"><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5"><img src="skins/input1.png" width="5" height="25" /></td>
<td background="skins/input3.png"><input name="myname" type="text" id="myname" style="border:solid 0px;" /></td>
<td width="6"><img src="skins/input2.png" width="6" height="25" /></td>
</tr>
</table></td>
<td width="272"><a href="index.asp">我有帳號了,登入?</a></td>
</tr>
<tr>
<td height="40"><div align="right"><b><font color="#FFFFFF">密 碼:</font></b></div></td>
<td><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5"><img src="skins/input1.png" width="5" height="25" /></td>
<td background="skins/input3.png"><input name="mypass" type="password" id="mypass" style="border:solid 0px;" /></td>
<td width="6"><img src="skins/input2.png" width="6" height="25" /></td>
</tr>
</table></td>
<td align="left"> </td>
</tr>
<tr>
<td height="40"><div align="right"><b><font color="#FFFFFF">確認密碼:</font></b></div></td>
<td><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5"><img src="skins/input1.png" width="5" height="25" /></td>
<td background="skins/input3.png"><input name="mypass2" type="password" id="mypass2" style="border:solid 0px;" /></td>
<td width="6"><img src="skins/input2.png" width="6" height="25" /></td>
</tr>
</table></td>
<td> </td>
</tr>
<tr>
<td height="40"><div align="right"><b><font color="#FFFFFF">學生名稱:</font></b></div></td>
<td><table width="200" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="5"><img src="skins/input1.png" width="5" height="25" /></td>
<td background="skins/input3.png"><input name="stuname" type="text" id="stuname" style="border:solid 0px;" /></td>
<td width="6"><img src="skins/input2.png" width="6" height="25" /></td>
</tr>
</table></td>
<td> </td>
</tr>
<tr>
<td height="40"> </td>
<td><label>
<input name="button" type="submit" class="nnt_submit" id="button" value="註冊" />
</label>
<a href="x_reg.asp">
<label>
<input name="button2" type="reset" class="nnt_submit" id="button2" value="重設" />
</label>
</a></td>
<td> </td>
</tr></form>
</table>
這是reg.htm的代碼全是htm的不講了,不過要提示一下,最好在用戶端進行判斷,使用者輸入資料的合法性,這樣有利於使用者體驗,這裡我不寫了,我在php實現·php 使用者登陸裡面詳細的寫了,
下面來看reg.asp的代碼
<!--#include file="inc/cn.asp" -->
<!--#include file="inc/function.asp" -->
<%
myname =Html_encode(Request.Form("myname"))
mypass =Html_encode(Request.Form("mypass"))
mypass2 =Html_encode(Request.Form("mypass2"))
stuname =Html_encode(Request.Form("stuname"))
If myname="" or mypass="" or mypass<>mypass2 or stuname="" Then
Response.Write("<script>alert('請認真填寫你的資訊!');history.back();</script>")
Elseif len(myanme)>15 or len(mypass)>15 or len(stuname)>5 or len(stuname)<2Then
Response.Write("<script>alert('你輸入資訊的長度不對,使用者名稱密碼長度1-15位,姓名長度2-5位');history.back();</script>")
Else
Sql="select * from stu_user where user_id='"&myname&"'"
Call Db_connect()
Rs.open Sql,conn,1,3
If Rs.eof Then
Rs.addnew
Rs("user_id")=myname
Rs("user_dj")="0"
Rs("User_name")=stuname
Rs("user_pwd")=mypass2
Rs.update
Session("Uid")=myname
Session("Udj")="0"
Session("Stuname")=stuname
Response.Redirect("iframe.asp")
Else
Response.Write("<script>alert('你的學號己被註冊,請聯絡管理員再試!');history.back();</script>")
End if
End If
%>
簡單吧,
註明:轉載請註明原處www.111cn.net