SQL PHP HTML ASP JavaScript articles and free scripts to download
 

Restricting access to member area in ASP


We can create a member only area in asp by using sessions. Userid of the member is stored in session variable and presence of this session variable is checked at the beginning of each page inside the member area. If session with userid is available then further script execution is allowed, otherwise the script execution is stopped and a message asking the member to login is displayed.

The session for every member is created at login page where a session with userid of the member is created after successful login of the member.

This member area pages links we can display once a member is successfully logged in but members may bookmark the URL of member area and may try to access the member area pages without logging in so session checking is a must for all these restricted pages.

We have to keep this checking if session status at the top of each page, here a better idea is to keep all these code inside one file and include that file at the staring of each page of member area. Like this ..



Now inside this check.asp file we will keep the code to check the user session status. Here it is .

<%
if (IsEmpty(Session("userid"))) then

Response.Write "Member area. Please <a href=''../login.asp''>login</a> to use this page "
Response.End

End if
%>
You can see in the above code if the Session(“userid”) is not available then IsEmpty function will return true and the code inside the if condition will be executed. The fist line will display the message with a link to login page and the next line Rsponse.End will stop further execution of the page.

This is a simple way to restrict access inside member only page for logged in users only.

Further readings
Checking visitor session and displaying login form or welcome message
Login form and data validation using ASP and MsSQL
Allowing access to logged in users inside member area using ASP
Changing Password inside member area using ASP
Sections
PHP
JavaScript
ASP
HTML
SQL
Photoshop
Articles SEO
All ASP Tutorials
ASP Sections
Ajax
Date and time
Declaring array
Form in ASP
Server.MapPath
Date Time & MSSQL
Select Query
File System Object
String Functions
Popular Tutorials
Managing two drop downs
Subscribe
Submit your email address and receive article and product notifications. Your email is safe with us.