Click here to Skip to main content
15,895,746 members
Articles / Web Development / IIS

Protecting pages with include files

Rate me:
Please Sign up or sign in to vote.
3.86/5 (4 votes)
14 Sep 2000CPOL 137.8K   1.2K   35  
An article on how to easily password protect a site using include files
<%response.buffer=true%>
<% 
	Dim strUserID
	Dim strPassword
	Dim bLoginOK

	strUserID   = Request.cookies("userID")
	bLoginOK    = false
	
	'check if the login is ok
	if (Len(strUserID) > 0) then
		'here you should use a database or a COM component				
		bLoginOK = StrComp(strUserID, "CodeProject") = 0
	end if
		
	'if the login isn't correct redirect to the login page
	if (not bLoginOK) then
		Dim strFile
		strFile = Mid(Request.ServerVariables("SCRIPT_NAME"), _
				InStrRev(Request.ServerVariables("SCRIPT_NAME"), "/") + 1)
		
		
		Response.Write "<form name=formLogin action='login.asp' method=post><input type=hidden name=destiny value='" & strFile & "'></form>"
		Response.Write "<script language=JavaScript>"
		Response.Write "document.formLogin.submit();"
		Response.Write "</script>"
		
		Response.End
	end if		
%>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect VisionOne AG
Switzerland Switzerland
XicoLoko is a brazilian developer based in Switzerland.

Comments and Discussions