asp登陸的代碼(asp用戶登錄代碼)
recordsetquotrsopen sql,conn,1,3 if rseof then responseWritequotalert#39用戶名或密碼錯(cuò)誤請(qǐng)重新登錄#39historygo1quotresponseend End If rsclose set rs=nothing connclose set conn=nothing responseRedirectquotxiugaiaspquot;1connectionasp里的代碼是lt set conn=servercreateobjectquotadodbconnectionquotconnopen quotprovider=data source=quotserverMapPathquotstudentmdbquot 2yanzhengasp里的代碼是lt!#include file=quotconnectionaspquot lt dim zhanghao,mima zhanghao=requestquotzhanghao;在表pUser213加個(gè)數(shù)字字段,比如ziduan,默認(rèn)值為0 登錄成功后就將diduan的值修改為了1 把 if rsquotziduanquot=1 then responsewrite quotquotchr13quotalert#39帳號(hào)已經(jīng)失效#39quotquothistorybackquotquotquotresponseend end if connexecutequotupdate pUser213 set ziduan=1 where y_username=#39quot;只需要在前面這樣就行了 if isnullsessionquotusernamequot or sessionquotusernamequot=quotquot then responseredirect quotdlaspquot responseend end if 為了方便管理,你應(yīng)該將上面寫成一個(gè)文件,比如checkadminasp然后在每個(gè)要調(diào)用的頁面的頂端寫入lt!#include file=quotcheckadminaspquot;會(huì)員登陸的時(shí)候做一個(gè)sessionquotusernamequot記錄,把用戶登陸的用戶名保存在里面,然后在顯示的地方做個(gè)判斷l(xiāng)t if sessionquotusernamequot=quotquot then 登錄框 lt%else% 會(huì)員信息 lt%end if%。
自己做個(gè)登陸頁面loginasp,一個(gè)FORM,方法設(shè)成method=quotpostquot,action=quotcheckloginaspquot,2個(gè)TEXTBOX,一個(gè)用戶名,一個(gè)密碼 一個(gè)按紐 驗(yàn)證頁代碼checkloginasp lt%@ LANGUAGE=quotVBSCRIPTquot % lt!#include file=quotconnaspquot lt!#include file=quotsessionaspquot lt% dim username,a u;登錄密碼 lt!登錄處理代碼 lt!#include file=quotconnaspquot lt if requestquerystringquotactquot=quotdenglquot then if requestquotnamequot=quotquot and requestquotpasswordquot=quotquot then responsewritequot請(qǐng)輸入用戶名和密碼!quotelse set rs=serverCreateObjectquotADODBRecordSetquot;protected void login_Clickobject sender, EventArgs e點(diǎn)擊登錄觸發(fā) if zhText == quotquot如果用戶名輸入為空,執(zhí)行if里的語句,彈出對(duì)話框‘卻確認(rèn)是否輸入了用戶名或密碼’ quot請(qǐng)確認(rèn)是否輸入了用戶名或密碼quot else if mmText == quotquot;檢查你的數(shù)據(jù)庫鏈接代碼正確不,跳轉(zhuǎn)一般放在登錄驗(yàn)證正確后,寫上這么一句 responseredirectxxasp。
1,indexasp 用戶登陸頁面 lt! #include file=quotconnaspquot lt! 悠悠長假期 會(huì)員 lt! body,td,th fontfamily 宋體 fontsize 14px 會(huì)員注冊系統(tǒng) 用戶名;登陸頁在登陸驗(yàn)證代碼略驗(yàn)證完畢后,寫以下代碼 lt responsecookiesquotusernamequot=rsquotusernamequotresponsecookiesquot等級(jí)quot=rsquot等級(jí)quotresponseRedirectquotchkaspquot chkasp lt if requestcookiesquotusernamequot=quot管理員quot then responseRedirectquotadminindexaspquotend if if r;responseWritequot=#39loginasp#39quotresponseEndend if rscloseconncloseset conn=nothing 并且在你每個(gè)后臺(tái)的頁面加上 lt if sessionquotusernamequot=quotquot or sessionquotpasswordquot=quotquot then Responsewritequotalert#39你是非法用戶,請(qǐng)登錄!#39quotResponsewrite quotdocument;lt!#include file=quotconnaspquot lt!#include file=quotincTS_SqlInaspquot lt!#include file=quotzjy_md6aspquot lt%dim admin,password,verifycode admin=replacetrimrequestquotadminquot,quot#39quot,quotquotpassword=zjy_md6replacetrimrequestquotpasswordquot,quot#39quot,quotquotverifycode=repla。
登錄按鈕代碼 protected void Button1_Clickobject sender, EventArgs e SqlConnection con = new SqlConnectionquotserver=localhostdatabase=boliuid=sapwd=saquotconOpenstring sql = quotselect * from admin where name=#39quot + TextBox1Text + quot#39 and password=#39quot + TextBox2;建議btnLogin_Click if rblUsertypeText == quot1quotZhiyuanLoginaccountname,passwordif rblUsertypeText == quot2quotAdminLoginaccountname,passwordif rblUsertypeText == quot3quotHuiyuanLoginaccountname, password這段代碼使用switch 原代碼如果不是第一個(gè)判斷命中,表示要多執(zhí)行一個(gè);登錄成功后跳轉(zhuǎn)到webform1aspx頁 else ResponseWritequotalert#39用戶名和密碼輸入不匹配,請(qǐng)重輸#39quot 2WebForm1aspx頁代碼using Systemusing using SystemLinqusing SystemWebusing using。
很簡單,用cookies記錄,先寫進(jìn)cookies,用以下語句 responsecookiesquotusernamequot=username responsecookiesquotpasswordquot=password responsecookiesquotusernamequotexpire=now+1 responsecookiesquotpasswordquotexpire=now+1 后兩句是設(shè)置了cookies的時(shí)間記憶期限,這里是記住一天,你想要多長時(shí)間都可以自己設(shè)置。
ConnOpen strConn 改成set rs = servercreateobjectquotadodbrecordsetquotsql = quotselect * from G_User where G_UserName=#39quot username quot#39quotrsopen sql,conn,1,1。
掃描二維碼推送至手機(jī)訪問。
版權(quán)聲明:本文由飛速云SEO網(wǎng)絡(luò)優(yōu)化推廣發(fā)布,如需轉(zhuǎn)載請(qǐng)注明出處。