We can display a welcome message to a visitor inside a member area based on his session status. If the member has not logged in then we can ask him to login. You must have observed in many sites and forums you will get a welcome message if you are logged in and the same place will show login form or link to login form if you are not logged in. How this is done ? We will learn that.
If the member is logged in then userid of the member will be available in session variable. So we will try to read the value of the session variable and display a welcome message like this
If session variable is not present then we will display a login window or show a link to login page like his
We will be using one if condition in ASP to check the session and display the welcome message if userid is present , else we will show the login form. Here is the code to do this
<% if (IsEmpty(Session("userid"))) then %>
<form method=post action=loginck.asp>
<table border="0" cellspacing="0" cellpadding="0" align=center>
<tr><td>User Id </td><td><input type=text name=userid></tr>
<tr><td>Password</td><td><input type=password name=password></tr>
<tr><td colspan=2 align=center><input type=submit value=Login></td></tr>
Response.Write " Welcome " & Session("userid") & " <a href=logout.asp>Click here to log out</a>"