2011-06-10 74 views
3

如果我有一個登錄頁面獲得用戶名和密碼的用戶輸入,我將如何將該信息發佈到另一個頁面,該頁面將用於存儲潛艇和程序,以便其他頁面將包含該頁面我可以最小化我輸入連接字符串的次數。經典的asp密碼驗證sql

所以我有login.asp我想登錄憑證,以include.asp永遠不會被打開,如果用戶登錄詳細信息是正確的,然後將被引導到table.asp。如果不正確,它應該在login.asp頁面中顯示一條錯誤消息。

我提供了永遠不會被用戶低於

Dim objCon, SQL, objRS 

'Connect to Database 
sub connect() 

    Set objCon = CreateObject("ADODB.Connection") 
    Set objRS = CreateObject("ADODB.Recordset") 
    objCon.Open "Provider=SQLOLEDB.1;Password=xxxx;Persist Security Info=True;User ID=xxxx;Initial Catalog=Customer;Data Source=xxxx" 
    SQL = "SELECT * FROM Customer" 
    objRS.open SQL, objCon 

end sub 


sub connectionClose() 

    objRS.close 
    objCon.close 

end sub 

回答

1

讓我發佈代碼標籤,以便它有所幫助。

所以你長了的login.asp,validateLogin.asp,table.asp(他們都得到include.asp)

的login.asp發佈憑據validatelogin.asp

一次validatelogin.asp

dim username : username = request.form("username") 
dim password: password = request.form("password") 
'here for security purpose u will want to replace all the single quote in username and password with 2x single quote (you do that to avoid SQL injection form bots/hackers 
username = replace(username ,"'","''") 
password = replace(password,"'","''") 
sqlValidateUser = "SELECT top 1 * FROM Customer where username='"&&"' and password = ''" 
set rsValidateUser = objCon.execute(sqlValidateUser) 
if not rsValidateUser.eof then 
    session("authentified") = "1" 
    response.redirect("table.asp") 
    response.end() 
else 
    response.redirect("YOUR_ERROR_PAGE.asp") 
    response.end() 
end if 
rsValidateUser.close 

然後在include.asp你也會想是這樣的:

'Validating if your NOT on login.asp or loginvalidate.asp ... if not Check if your logged in ... if not redirect to error page or login form 
    if not instr(lcase(request.servervariable("url")),"login.asp") > 0 and not instr(lcase(request.servervariable("url")),"validatelogin.asp") > 0 then 
     if session("authentified") = "1" then 
      response.redirect("your_Error_page.asp") 
     end if 
    end if 

不是100%肯定有關include.asp代碼我沒有驗證任何它,但它應該看起來像

0

可以看到在你的根文件夾include.asp文件的代碼創建一個\文件夾中包含。 在\包括添加一個「functions.asp」頁面,並把你的通用數據訪問功能在該頁面。包括沒有HTML - 只是服務器端腳本。

在你的認證頁面,添加#include指令指向您的文件夾包括:例如:

<!-- #include file = "../includes/functions.asp" --> 

然後從你的身份驗證頁面,您撥打functions.asp定義的任何功能。

+0

是的我已經做了我的include.asp文件,但我想知道如何設置我的login.asp文件中的include.asp中的變量,因爲我的表單將帶我到我的table.asp頁面,並將不會設置include.asp變量 – 2011-06-10 14:49:26

+0

我會做一個會話變量嗎? – 2011-06-10 14:52:01

+1

我會使用一個會話變量是的,一旦他登錄設置會話(「驗證」)=「1」...然後在你的include包括會話(「驗證」)<>「1」然後response.redirect「YOUR_ERROR_PAGE驗證。 asp「Response.end()end if – 2011-06-10 17:36:01