iron2000 Posted March 31, 2003 Share Posted March 31, 2003 How do can I display username on page after login? Something like the "Logged in as: " at the top of this page. Using ASP . Any ASP code examples? Link to comment Share on other sites More sharing options...
0 +Anarkii Subscriber² Posted April 1, 2003 Subscriber² Share Posted April 1, 2003 <%@ LANGUAGE="VBSCRIPT" %> <% pageTitle = "Counter" %> <% p_username = Request.form("p_username") p_password = Request.form("p_password") p_save = Request.form("p_save") set unrealDB = Server.CreateObject("ADODB.Connection") 'unrealDB.Open "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=d:\Chris\Website\UnrealNights\unreal.mdb" unrealDB.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & SERVER.MapPath("..\unreal.mdb") & ";" sqlText="select * from members where username='"&p_username &"'" set userSet = unrealDB.Execute(sqlText) if userSet.EOF then 'No such username, so the recordSet is empty Response.Redirect "login.asp?retry=username" else 'The username is good, now let's check the password real_password = trim(userSet("password")) if p_password = real_password then 'Password is good, too Response.cookies("isLoggedInAs")("username") = p_username Response.cookies("isLoggedInAs")("first_name") _ = userSet("first_name") if p_save = "yes" then Response.cookies("isLoggedInAs").expires =_ #December 31, 2999 00:00:00# end if else 'Username is good, but password is wrong Response.Redirect "login.asp?retry=password" end if end if %> <% pageTitle = "Counter" %> <!--#include file="pagetop.htm"--> <hr noshade color="#BB6622" align="left"> <h1 align="left">You are now logged in.</h1> <font size="5">Welcome back, <%= userSet("first_name")%>! <% userSet.Close set userSet = Nothing unrealDB.Close set unrealDB = Nothing %> <br> </font><table width="75%" border="0" align="center"> <tr> <td>You are currently logged in as: <font color="red"><%= Request.cookies("isLoggedInAs")("username")%></font> </td> </tr> </table> <meta http-equiv="REFRESH" content="3; url=../index.asp" > Now returning you to the main page in 3 seconds...<br> <br> <br> <p> <p> <hr noshade color="#BB6622" align="left"> <h1 align="left"> </h1> <!--#include file="pagebottom.txt"--> </p> </body> </html> Link to comment Share on other sites More sharing options...
0 +Anarkii Subscriber² Posted April 1, 2003 Subscriber² Share Posted April 1, 2003 what that does is open a connection to a database, requests the username stored in the database to that of a cookie on the pc, then shows it on the screen in the index.asp page if theres a match. if not it promps you to goto the login page to login. some code might need to be changed, but you should see how i do it Link to comment Share on other sites More sharing options...
Question
iron2000
How do can I display username on page after login?
Something like the "Logged in as: " at the top of this page.
Using ASP .
Any ASP code examples?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts