ASP應用中的應用函數

來源:互聯網
上載者:User
1,經常寫些系統,那麼一般都是從登入程式開始,每接一個系統就寫一次登入,好麻煩。
乾脆直接做個登入驗證函式吧,對我來說,大都情況可以勝任了:)
<%
Function chk_regist(requestname,requestpwd,tablename,namefield,pwdfield,reurl)
dim cn_name,cn_pwd
cn_name=trim(request.form(""&requestname&""))
cn_pwd=trim(request.form(""&requestpwd&""))
if cn_name="" or cn_pwd="" then
response.Write("<script language=javascript>alert(""請將帳號密碼填寫完整,謝謝合作。"");history.go(-1)</script>")
end if
Set rs = Server.CreateObject ("ADODB.Recordset")
sql = "Select * from "&tablename&" where "&namefield&"='"&cn_name&"'"
rs.open sql,conn,1,1
if rs.eof then
response.Write("<script language=javascript>alert(""沒有該會員ID,請確認有沒有被申請。"");history.go(-1)</script>")
else
if rs(""&pwdfield&"")=cn_pwd then
session("cn_name")=rs(""&namefield&"")
response.Redirect(reurl)
else
response.Write("<script language=javascript>alert(""提醒,您的帳號和密碼是不吻合。注意數字和大小寫。"");history.go(-1)</script>")
end if
end if
rs.close
Set rs = Nothing
End Function
%>

參數說明:
chk_regist(requestname,requestpwd,tablename,namefield,pwdfield,reurl)
requestname 為接受HTML頁中輸入名稱的INPUT控制項名
requestpwd 為接受HTML頁中輸入密碼的INPUT控制項名
tablename 為資料庫中儲存註冊資訊的表名
namefield 為該資訊表中存放使用者名稱稱的欄位名
pwdfield 為該資訊表中存放使用者密碼的欄位名
reurl 為登入正確後跳轉的頁
引用樣本如下:
<%
call chk_regist("b_name","b_pwd","cn_admin","cn_name","cn_pwd","admin.asp")

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.